?
Solved

CStringArray memory leak

Posted on 2004-03-26
7
Medium Priority
?
1,191 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

770 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