[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

CStringArray memory leak

Posted on 2004-03-26
7
Medium Priority
?
1,243 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:Spook73
7 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 10691256
CStringArray::RemoveAll() should free all the CStrings in the array. Show your code please.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10691380
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
 
LVL 14

Expert Comment

by:wayside
ID: 10691824
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Spook73
ID: 10691894
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
 
LVL 23

Accepted Solution

by:
chensu earned 375 total points
ID: 10692500
I don't think this causes any memory leaks. Create a new application and call arrayfn() repeatedly to see if it is reproducible.
0
 

Expert Comment

by:sgoglia
ID: 10832165
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
 
LVL 23

Expert Comment

by:chensu
ID: 10944129
>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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question