Solved

CStringArray memory leak

Posted on 2004-03-26
7
1,094 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
Comment Utility
CStringArray::RemoveAll() should free all the CStrings in the array. Show your code please.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:Spook73
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now