Spook73
asked on
CStringArray memory leak
I have created a CStringArray ar_Data within a function which is populated with a list of CStrings, for example 5 strings. I am constantly reusing the function and therefore the CStringArray to store different Strings, for example 7 strings, then 3strings, etc. My problem is that when I use the function ar_Data.RemoveAll(); it is not releasing the memory so eachtime I use the function the memory overhead increases. Can someone suggest a way to totally destroy the CStringArray and release the memory so it can be reused.
CStringArray::RemoveAll() should free all the CStrings in the array. Show your code please.
How do you know that the memory is not released? Are you seeing memory leaks reported when you run the program in the debugger, or are you using a memory debugger (like Purify)?
How are you determining that your "memory overhead" is increasing? If you are using the task manager, increases in the numbers it reports don't necessarily mean you are leaking memory, it could mean memory is getting fragmented or the OS is letting you keep more of your memory resident in physical memory or whatever.
ASKER
khkremer: I'm using a Pocket PC and the memory in use increases each time I run the routine.
chensu: The code is as follows:
void arrayfn()
{
CStringArray ar_Data;
ar_Data.add("text");
//read ar_Data
ar_Data.RemoveAll();
}
chensu: The code is as follows:
void arrayfn()
{
CStringArray ar_Data;
ar_Data.add("text");
//read ar_Data
ar_Data.RemoveAll();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I'm a little late but...
Calling RemoveAll() doesn't release the actual object memory but just the pointer. So what you have to do is delete a CString object, and then call RemoveAt.
Calling RemoveAll() doesn't release the actual object memory but just the pointer. So what you have to do is delete a CString object, and then call RemoveAt.
>So what you have to do is delete a CString object, and then call RemoveAt.
For CStringArray, you don't have to do that.
For CStringArray, you don't have to do that.