Re: memory managment of std::list on linux

From: Nils O. Selåsdal (noselasd_at_frisurf.no)
Date: 03/30/04


Date: Tue, 30 Mar 2004 07:37:06 GMT

In article <c4ai80$csp$1@fair.qualcomm.com>, Jonh Smith wrote:
> Hi, there,
>
> Could some one please tell me how to force std::list to free its memory it
> once allocated. I had a situation where my application push_back()'ed
> millions of items to the list. I monitored the top showing hundreds of
> megabytes being consumed by my application. My application later erase()'ed
> all items from the list, but the top still showed the same amount of memory
> being occupied by my application. My application continues running, but I
> want my application to give the memory it once used back to the system so
> that other applications can use them. Below is the section of code and its
> corresponding top output. Thanks a lot!
>
This is the way memory allocation work. You allocate memory on the heap,
the heap is like a stack, it grows an shrinks from the bottom(or the top),
when you release memory, it's released back to the memory
manager and reused on further malloc/new's. It is not released
back to the OS. That is in special cases it is, for big single
allocation mmap is used by the allocator to obtain memory, and
munmap will release it back to the OS. And if the allocator sees
that there are lots of free memory at the top of the heap, it
can shrink it.All this depends on the OS's(libc) memory allocator
usually.
On the other hand, you have virtual memory, so you shouldn't run short
on physical memory. The unused pieces of memory will just be swapped out.



Relevant Pages

  • Re: "Physical" memory bounds
    ... This gets tedious with discontiguous memory but I don't see ... is placed in the System Heap. ... Out of this, each task's stack is ... The dynamic memory allocator base allocator will use this label as the ...
    (comp.arch.embedded)
  • Re: Error Raising and Memory in VB (general question)
    ... > object is terminated go out of scope, and the memory is also released. ... But why are you saying it uses stack? ... I think we are dealing with heap memory here. ... "COM's IMalloc allocator: ...
    (microsoft.public.vb.general.discussion)
  • Re: [PATCH/RFCv4 2/6] mm: cma: Contiguous Memory Allocator added
    ... Various chips require contiguous blocks of memory to operate. ... +* Contiguous Memory Allocator ... The Contiguous Memory Allocator (CMA) is a framework, ... The main role of the framework is not to allocate memory, ...
    (Linux-Kernel)
  • Re: Critique on my solution for an exercise. (check if a date is valid)
    ... simplify anything, when done in Forth. ... N times the allocation of one fixed sized object through dynamic memory. ... Thus you rely on general memory allocator, which isn't written in Forth way ... scalability problems, which is bullshit. ...
    (comp.lang.forth)
  • Re: Possible to set cpython heap size?
    ... If the heap is relatively small, GC has to do some work ... VM and physical memory is committed, since it needs to be used. ... a custom allocator, which uses 256kB arenas malloced from the OS on ...
    (comp.lang.python)