[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NSAutoreleasePool does not free all memory
From: |
Richard Frith-Macdonald |
Subject: |
Re: NSAutoreleasePool does not free all memory |
Date: |
Mon, 30 Apr 2001 05:49:52 +0100 |
On Sunday, April 29, 2001, at 09:39 PM, Gerald Siebke wrote:
Hi,
I have installed the latest cvs-version on NetBSD 1.5_ALPHA
with the default egcs-1.1.2.
I have the following problem with an NSAutoreleasePool:
The allocated memory inside the NSAutoreleasePool is not completely
freed outside.
CASE #1
-------
line '16' contains : autorelease
before allocation : 4.9 MB
after allocation : 7.8 MB
after destroy NSAutoreleasePool : 7.0 MB <-- why ???
CASE #2
-------
we changed in line '16' : autorelease --> release
before allocation : 4.9 MB
after allocation : 7.5 MB
after destroy NSAutoreleasePool : 4.9 MB <-- this is okay !
The free() call can only give memory back to the operating system if it
has
a nice big simple block of unused memory extending to the end of the
allocated memory range. If that's not the case, the memory will remain
'owned' by the program and will be re-used in later calls to malloc().
If you use autorelease, as well as allocating memory for the strings and
array,
yopu allocate some memory for the autorelease pool itsself, and as the
pool
grows, this memory is reallocated to make the pool bigger. This means
that
somewhere near the end of the allocated memory will be memory used by an
autorelease pool.
Autorelease pool memory is *not* freed (unless the thread they belong to
is terminated) ... the autorelease pool objects are
cached for later re-use ... so this memory will remain in use, and will
stop the whole block of memory being returned to the operqating system.
This is of course harmless, since the memory will be re-used the next
time any
object is allocated, (so memory usage will not grow indefinately) and if
nothing
ever is allocated again, it will be paged out to disk.