Re: NSXMLParser frees itself on error?
Re: NSXMLParser frees itself on error?
- Subject: Re: NSXMLParser frees itself on error?
- From: "Stephen J. Butler" <email@hidden>
- Date: Wed, 6 May 2009 22:31:23 -0500
On Wed, May 6, 2009 at 5:49 PM, Jeff Johnson
<email@hidden> wrote:
> I find this idea somewhat suspect. It seems to undermine the basic function
> of the autorelease call, which is delay a release until later.
>
> The reasoning here could be taken to the point of absurdity. This is because
> a 'callee' (self, that is) never knows whether the caller has wrapped the
> called method in an inner autorelease pool. Thus, the callee never knows
> whether its own calls to autorelease will be subsequently turned into
> releases by the drained pool immediately upon returning from the called
> method. Is the callee never supposed to use autorelease, to be safe?
>
> From the callee's perspective, a call to autorelease defers the release
> until the end of the event loop. If the caller does anything to shorten the
> lifetime of objects, that's the callers own fault and responsibility.
>
> In my opinion, the above code is very questionable. You're just asking for
> trouble if you create an autorelease pool yourself and then call out to the
> unknown, especially to an object for which you only have a weak reference
> and who is probably your owner, the delegate. You are purposely shortening
> the lifetime of objects, so you're responsible for making sure nothing
> important gets deallocated prematurely.
Listen: autorelease in its simplest form means "release this object
sometime after the current method returns." No guarantees are made
beyond that. It could be released earlier if you're managing your own
autorelease pools. If you think the Apple docs guarantee anything
else, then you need to go back and carefully re-read them.
Now, with that in mind, take a look at the example I gave. For
autorelease to work how you want it to, you need it to delay release
AT LEAST TWO method returns. The return from the delegate callback,
and the return from whatever called that method. There is absolutely
nothing in the autorelease contact that says it will defer release
this long. Which is why autorelease, in this example, is a very bad
idea.
_______________________________________________
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