Not freeing memory in C array

This C code (compiled as C ++) does not free memory. The program starts at 992kB on a "new" line, then after memory allocation it goes down to 10MB. After freeing up memory, it is reduced to 3 MB. Even deleting delete [] does not erase memory. What am I doing wrong?

INT iSize=8192;

struct sUsernameA
{
TCHAR *sUsername;
};

sUsernameA *sArr = new sUsernameA[iSize]();

for (INT i=0;i<iSize;i++)
{
sArr[i].sUsername = (TCHAR*)calloc(512,sizeof(TCHAR));
}


for (INT i=0;i<iSize;i++)
{
free(sArr[i].sUsername);sArr[i].sUsername = NULL;
}

delete [] sArr;

      

+3


source to share


1 answer


There are various approaches to memory management. For example, you can find an explanation for some of them on wikipedia . I'm used to seeing dlmalloc, but obviously there are many other methods.



In any case, all methods require scafdolding, and also some of them try to guess the next steps to manage memory by the programmer, so the only way to make sure that you have completely returned all memory to the OS is to exit the program.

0


source







All Articles