Re: Memory problems (possibly very easy question)
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Tue, 28 Nov 2006 11:50:42 -0500
The question sounds more like the "I freed the memory, why didn't my program get smaller?"
(Usually based on some value like theprogram size in Task Manager). The program doesn't
get smaller because it isn't supposed to get smaller; that's not how storage allocators
work. It is a common delusion that if you free storage your program should get smaller;
it can't, and it won't. The subtleties of this are discussed in my essay on storage
mangement on my MVP Tips site.
joe
On 28 Nov 2006 05:22:41 -0800, "peter koch" <peter.koch.larsen@xxxxxxxxx> wrote:
Joseph M. Newcomer [MVP]
hamishd skrev:
Hello,
In my application I create some large vectors to hold data. For
example:
std::vector<DataItemClass*> MyData;
DataItemClass * DataItem;
for(i=0;i<SomeLargeLimit;i++){
DataItem = new DataltemClass;
MyData.push_back(DataItem);
}
So while my application is running, I can watch in the "Windows Task
Manager" under "Processes" my application's mem usage increase as I
allocate more memory. Eg, say to 150,000KB.
How do I release this memory?
I go:
for(i=0;i<MyData.size();i++)
delete(MyData[i]);
MyData.clear();
But my mem usage does not reduce... so when i run the process a few
times the usage gets really really large, and windows gives me virtual
memory usage warnings (or similar).
This means there is a problem somewhere.
When I run the application in debug mode, the same thing occurs, and i
can confirm the "delete" operations are being executed. MSVC++ 6.0 does
not show any memory leaks, so why is my memory usage not clearing?
Because you made a fault elsewhere. Can you provide a complete program
to demonstrate your fault? Do that - e.g. providing a dummy
DataItemClass and see if the problem reproduces. If it does, post
again. My suspicion is that the culprit is the DataItemClass
destructor.
By the way: VC++ 6.0 is REALLY old. You ought to replace it with
something more modern and more C++.
/Peter
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: Memory problems (possibly very easy question)
- From: peter koch
- Re: Memory problems (possibly very easy question)
- Prev by Date: Re: time-server question
- Next by Date: Re: how to let a topmost window follow its parent window?
- Previous by thread: Re: Memory problems (possibly very easy question)
- Next by thread: Re: Memory problems (possibly very easy question)
- Index(es):