This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
re: memory allocation
- From: Dan Kegel <dank at kegel dot com>
- To: GCC Mailing List <gcc at gcc dot gnu dot org>, gcc-help at gcc dot gnu dot org, laczo dot tibor at pro dot hu
- Date: Sat, 13 Sep 2003 08:26:14 -0700
- Subject: re: memory allocation
- Reply-to: gcc-help at gcc dot gnu dot org
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