• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSXMLParser frees itself on error?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSXMLParser frees itself on error?
      • From: Jeff Johnson <email@hidden>
References: 
 >NSXMLParser frees itself on error? (From: Mike Manzano <email@hidden>)
 >Re: NSXMLParser frees itself on error? (From: Jesper Storm Bache <email@hidden>)
 >Re: NSXMLParser frees itself on error? (From: "Stephen J. Butler" <email@hidden>)
 >Re: NSXMLParser frees itself on error? (From: Jeff Johnson <email@hidden>)
 >Re: NSXMLParser frees itself on error? (From: Marcel Weiher <email@hidden>)
 >Re: NSXMLParser frees itself on error? (From: Jeff Johnson <email@hidden>)
 >Re: NSXMLParser frees itself on error? (From: Marcel Weiher <email@hidden>)
 >Re: NSXMLParser frees itself on error? (From: Jeff Johnson <email@hidden>)
 >Re: NSXMLParser frees itself on error? (From: Marcel Weiher <email@hidden>)
 >Re: NSXMLParser frees itself on error? (From: Jeff Johnson <email@hidden>)

  • Prev by Date: Re: NSXMLParser frees itself on error?
  • Next by Date: Re: Help Making Shell Script Accept Spaces
  • Previous by thread: Re: NSXMLParser frees itself on error?
  • Next by thread: Re: NSXMLParser frees itself on error?
  • Index(es):
    • Date
    • Thread