Re: memory managment of std::list on linux
From: Nils O. Selåsdal (noselasd_at_frisurf.no)
Date: 03/30/04
- Next message: Bernd Strieder: "Re: memory managment of std::list on linux"
- Previous message: Måns Rullgård: "Re: IDE for C: KDevelop vs Emacs vs Other"
- In reply to: Jonh Smith: "memory managment of std::list on linux"
- Next in thread: Bernd Strieder: "Re: memory managment of std::list on linux"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Next message: Bernd Strieder: "Re: memory managment of std::list on linux"
- Previous message: Måns Rullgård: "Re: IDE for C: KDevelop vs Emacs vs Other"
- In reply to: Jonh Smith: "memory managment of std::list on linux"
- Next in thread: Bernd Strieder: "Re: memory managment of std::list on linux"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|