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.
Spook73Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
chensuConnect With a Mentor Commented:
I don't think this causes any memory leaks. Create a new application and call arrayfn() repeatedly to see if it is reproducible.
0
 
chensuCommented:
CStringArray::RemoveAll() should free all the CStrings in the array. Show your code please.
0
 
Karl Heinz KremerCommented:
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)?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
waysideCommented:
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.
0
 
Spook73Author Commented:
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();
}
0
 
sgogliaCommented:
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.
0
 
chensuCommented:
>So what you have to do is delete a CString object, and then call RemoveAt.

For CStringArray, you don't have to do that.
0
All Courses

From novice to tech pro — start learning today.