Re: NSXMLParser frees itself on error?
Re: NSXMLParser frees itself on error?
- Subject: Re: NSXMLParser frees itself on error?
- From: Marcel Weiher <email@hidden>
- Date: Thu, 7 May 2009 00:38:44 -0700
On May 6, 2009, at 23:56 , Jeff Johnson wrote:
On May 7, 2009, at 12:27 AM, Marcel Weiher wrote:
OK, quiz time: the reason for NSMutableString to relinquish
ownership is to (a) release the object (b) allow someone else to
take ownership?
Answer: always (a), sometimes (b), and sometimes (c).
Now you're being even more silly.
EXACTLY. Autorelease allows ownership transfer from called
methods to occur without thrusting ownership on those that don't
want it.
That's one use, anyway.
No. That is what you need autorelease for. Anything else is fluff.
3) As I said below, "It's of course somewhat easier to work around
this problem given the API of NSXMLParser, but you can't generalize
to all delegate methods based on NSXMLParser."
Actually, I can generalize to all synchronous message sends.
The delegate never has ownership of the object.
Usually the delegate is the owner. That is, the owner allocates the
object and sets itself as the delegate.
That's your opinion. Doesn't matter though: it is in the role of the
owner that the object gets to release the object, not in the role of
the delegate.
According to your argument, you can't even assume it's safe in
some kind of "didFinish" delegate method, because the object could
still do weird stuff after calling didFinish on the delegate.
The only thing that would be weird here would be if the caller were
actually deallocated when it returns from sending the "didFinish"
message. Look at the following.
It's of course somewhat easier to work around this problem given
the API of NSXMLParser, but you can't generalize to all delegate
methods based on NSXMLParser. What about more async delegate like
NSURLConnection?
It is the *owner* of the object that releases it, not the delegate.
As above, usually they're the one and the same.
Even if they are the same object, it is in the owner role that the
object gets to release the object.
The claim by Stephen J. Butler was, "it's never safe to release/
autorelease an object from inside one of it's delegate calls." I
agree about release, but not about autorelease.
Well, your agreement is neither sought nor required, what Stephen said
is correct.
And NSXMLParser is not a good example to generalize upon, because as
we see with your code fragment, you don't even need delegate methods
to know when it's done.
PRECISELY.
I'm still waiting to hear a solution for the fully async cases.
What "fully async" case? Message-sending in Objective-C is synchronous.
Marcel
_______________________________________________
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