Possible Duplicate:
Problem usage memory in C
I have problem: operator "delete" does not return allocated memory.
Peace of code to illustrate how I use "delete" operator. Сertainly, before this code called all pointers created with operator "new" at other parts of the program:
std::multimap<std::string, Container*>::iterator it;
for ( it = MAPX.begin() ; it != MAPX.end(); )
{
Container* ptr_container = it->second;
// delete every object at the container
std::multimap<unsigned int, TMB*>::iterator it_tmb;
for ( it_tmb = ptr_container->map_thumbs.begin() ; it_tmb != ptr_container->map_thumbs.end(); )
{
TMB* ptr_currentGlobalThumb = it_tmb->second;
ptr_container->map_thumbs.erase( it_tmb++ ); // erase from map
delete ptr_currentGlobalThumb; // delete at the memmory
}
delete ptr_container; // lets delete empty container now
MAPX.erase( it++ ); // and erase it from map
}
Before I start this peace of code I look at my top
and ps aux
output at FreeBSD and see that program use 241M of memory:
ps: abrahab 21351 3.5 7.3 263108 246932 ?? S 3:19PM 1:50.94 program
top: 21351 abrahab 8 -8 0 257M 241M biord 2 0:47 8.30% program
After cleaning process nothing changed! As program use 241M of RAM, so program continued to use memory (not deallocated). Why?
After restart of program, I see that memory returned for system (of course):
abrahab 71595 0.0 5.0 185284 170360 ?? I 4:50PM 0:18.62 program
EDIT: 1) So how can I control real memory usage of my program when its running? 2) Seems that program crash(end without the .core file) when its begin to use ~1Gb of memory on 32bit FreeBSD - is it possible that FreeBSD "end" program that use too much memory?