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: Jim Correia <email@hidden>
- Date: Fri, 15 Feb 2008 08:41:29 -0500
On Feb 14, 2008, at 11:36 PM, j o a r wrote:
On Feb 14, 2008, at 7:57 PM, Jim Correia wrote:
But -release is a no-op in GC code. NSAutoreleasePool will never
get the message. So we need a new message that we can send
NSAutoreleasePool that it will actually get when running in GC
mode. And for convenience, in non-GC mode it should do the same
thing as -release always did, to provide a single, simple idiom for
inner autorelease pools that will work in either GC or non-GC mode.
Yes, strictly speaking, it is inconsistent. But also necessary; the
alternatives would be uglier.
I don't know if I agree. Rather than repeatedly creating and
destroying a local autorelease pool in a non-GC app, why not instead
using "-drain" with the same type of semantics as in GC?
Well, I was trying to provide a plausible explanation for why we ended
up with -drain as a synonym for -release, not second guess the
decision with the advantage of hindsight (and the disadvantage of not
having all the facts before me.).
---------------------------------------------
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
for (id foo in foos)
{
// Stuff...
[pool drain];
}
[pool release];
---------------------------------------------
Much better IMO. The above would work fine in both GC and non-GC,
and it doesn't suffer from the completely unexpected behaviour of
having (drain == release) in non-GC.
This doesn't suffer from the problem where -drain is now a special
case and is equivalent to release in a non-GC app. (But as I
mentioned, NSAutorelease pool was already a bit of a special case
anyway.)
It has the disadvantage that it is a bigger change in the previous
idiom for existing code which destroyed and created a new pool every
loop iteration. (Or every N loop iterations.)
(And there certainly could have been additional issues we haven't
considered.)
Now, this is all a moot point of course... :-)
Indeed. -drain is what it is, and is documented that way :-)
Jim
_______________________________________________
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