Re: In-loop releasing of objects does not free memory?
Re: In-loop releasing of objects does not free memory?
- Subject: Re: In-loop releasing of objects does not free memory?
- From: Adam P Jenkins <email@hidden>
- Date: Fri, 15 Feb 2008 13:56:36 -0500
On Feb 15, 2008, at 12:15 PM, Jim Correia wrote:
On Feb 15, 2008, at 11:27 AM, Adam P Jenkins wrote:
I still don't understand. Why does it matter that the release
message to a NSAutoreleasePool would be a noop when running in GC
mode? Isn't autorelease also a noop? In which case the whole
NSAutoreleasePool is just a noop, since nothing would ever actually
get added to it. So I still don't understand the need for the
drain method as it's currently defined.
There aren't any autoreleased objects in a GC app in the traditional
sense, but there will be uncollected garbage.
-drain provides a single mechanism which you can use in a tight loop
which generates lots of temporary objects to
- in GC mode hints to the collector that it should collect some
garbage
- in non-GC mode, pop the autorelease pool
which have similar effects on the high water mark of helping you
keep down your high water mark.
Ok, so the intended pattern for using drain when you want to write
code which works in both GC and non-GC mode is something like:
for (i = 0; i < 1000; i++) {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
// do some work
[pool drain];
}
where [pool drain] differs from [pool release] in that it does
something useful in GC mode as well, whereas [pool release] would only
do something useful in non-GC mode. I think I understand now. Thank
you.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden