This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problems with releasing memory for the "vector"!


Hao Xia wrote:
Hi, guys

I think the best way is to attach a test program, atest.cpp.

I was releasing memory from a nested vector:

vector< vector<someclass> > F;

But never get it done...
<snip>

As you can see, memory was not released even for non-existing variable.

Any comments?

This is just how memory allocation works.. the memory is kept in an internal cache, so it can be given back out without having to go and ask the operating system for some more memory.


Try altering your program to have the code in main twice. I did this, and got this output:

   RSS      VSZ %MEM COMMAND
121780   156868 15.5 ./a.out
Before clear --------------------------
   RSS      VSZ %MEM COMMAND
109552   144708 13.9 ./a.out
After clear ---------------------------
   RSS      VSZ %MEM COMMAND
121840   156996 15.5 ./a.out
Before clear --------------------------
   RSS      VSZ %MEM COMMAND
109552   144708 13.9 ./a.out
After clear ---------------------------

as you can see, modulo some very small differences, the memory is being reused the second time through.

I'm unsure if it is possible to force the memory to be released back to the operating system, and how useful such a thing would be anyway...

Chris


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]