Home:ALL Converter>Not freeing memory in a C array

Not freeing memory in a C array

Ask Time:2015-06-20T02:41:49         Author:JeffR

Json Formatter

This C code (compiled as C++) is not freeing memory. The program starts out with 992kB on the 'new' line, then after allocating memory, it goes to 10MB. After freeing the memory, it only goes down to 3MB. Even doing a delete[] doesn't erase the 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;

Author:JeffR,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30945164/not-freeing-memory-in-a-c-array
yy