Re: Memory management about async object
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