Re: what is this memory usage
On 29 Oct, 15:15, CMOS <manu...@millenniumit.com> wrote:
consider the below code. it just creates a map and inserts 51000000
elements. when i check the memory usage , it shows an increase of
memory after the loop. the increase is around 2mb. i used "ps aux"
command and use the VSZ value.
why is this happening? i dont see any memory leaks as nothing is
created in heap/free store.
is this some kind of a memory fragmentation issue?
// memory ckeck 1 goes here
std::map<std::string, int> mm;
for(int i=0; i<51000000; ++i)
s = i;
mm[s] = i;
// memory ckeck 2 goes here, and there is an increase in memory
Isn't that right? You have created objects between memcheck 1 and 2,
and so should an increase in memory use.
The map is local to the block, as soon as the block closes, the map
should be destroyed and the memory should be released.
To the OP: checking the memory using OS specific tools is OS specific,
and any results cannot be explained in terms of C++ language. If you
are concerned with leak or fragmentation, use the proper tools to find
out whether those conditions are present, but we in comp.lang.c++ do
not have a way to help you.
Often the OS gives the running process more memory as it needs it, but
does not claim it back when the process releases the memory internally
(like when calling 'free' for, or 'delete'ing, a pointer). You need
to use other means to verify or dismiss your doubts in the correctness
of the memory consumption of your process.
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask