memory allocation
Dan Kegel
dank@kegel.com
Sat Sep 13 15:00:00 GMT 2003
Laczó Tibor wrote:
[ In Redhat Linux, how come calling delete on objects in C++
doesn't return memory to the operating system? Even after
my program deletes all its big objects, RSS doesn't shrink. ]
That's an FAQ. http://www.lysator.liu.se/c/c-faq/c-3.html says
Q. I have a program which mallocs but then frees a lot of memory,
but memory usage (as reported by ps) doesn't seem to go back down.
A. Most implementations of malloc/free do not return freed memory to
the operating system (if there is one), but merely make it available
for future malloc calls within the same process.
glibc's manual also mentions this:
http://www.gnu.org/manual/glibc-2.2.5/html_node/Freeing-after-Malloc.html#Freeing%20after%20Malloc
which says
"Occasionally, free can actually return memory to the operating system
and make the process smaller. Usually, all it can do is allow a
later call to malloc to reuse the space. In the meantime,
the space remains in your program as part of a free-list used internally by malloc."
Please take this discussion to gcc-help@gcc.gnu.org
or maybe comp.lang.c++.
gcc@gcc.gnu.org is for gcc maintainers, not users.
- Dan
--
Dan Kegel
http://www.kegel.com
http://counter.li.org/cgi-bin/runscript/display-person.cgi?user=78045
More information about the Gcc-help
mailing list