• 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: Memory management about async object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory management about async object


  • Subject: Re: Memory management about async object
  • From: ico <email@hidden>
  • Date: Tue, 28 Dec 2010 17:28:18 +0800

Hi Stephen,

Thanks for your reply, so there is no any perfect solution for this kind of
problem?
And can you give me a specific example to demonstrate why why it is not safe
to
release these async objects inside a callback method and why not safe to
autorelease it?
Thanks.

On Tue, Dec 28, 2010 at 4:13 PM, Stephen J. Butler <email@hidden
> wrote:

> On Tue, Dec 28, 2010 at 12:18 AM, ico <email@hidden> wrote:
> > My question is, when should I release the myHandler? Should I release it
> in
> > the myCallback, but after
> > myCallback method finishes, it will return point 1 indicated as above,
> and
> > that myHandler instance is just
> > released.
> >
> > Or there is a better way to deal with async object? I also wonder how
> > NSURLConnection class handle this itself.
>
> I think most people agree that it isn't safe to release inside a
> callback for exactly this reason. I've argued before that it isn't
> safe to autorelease either, but people disagree. I think that, in this
> case where you wrote the data handler, it is safe to autorelease if
> you're careful.
>
> Another solution is to have the handler retain itself as long as
> there's a pending request. Then it doesn't matter much how you release
> it in the callback.
>
> Finally, you can try to write your data handler so that it doesn't do
> anything with "self" after it calls the callback. But this is very
> fragile and hard to maintain.
>



--
==========================
Life isn't about finding yourself.
Life is about creating yourself.
_______________________________________________

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

References: 
 >Memory management about async object (From: ico <email@hidden>)
 >Re: Memory management about async object (From: "Stephen J. Butler" <email@hidden>)

  • Prev by Date: Re: Drawing to two CALayers at once (or pretend to)?
  • Next by Date: Runtime Error: Incompatable applications
  • Previous by thread: Re: Memory management about async object
  • Next by thread: Re: Memory management about async object
  • Index(es):
    • Date
    • Thread