Solved

CStringArray memory leak

Posted on 2004-03-26
7
1,118 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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 125 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Rewrite URL With Encoded Characters 6 78
Creating Labels and Frequency list style reports in SAS code 9 98
not able to insert into temp table 68 162
modThree challenge 4 90
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

786 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