Re: Memory management about async object
Re: Memory management about async object
- Subject: Re: Memory management about async object
- From: "Stephen J. Butler" <email@hidden>
- Date: Tue, 28 Dec 2010 02:13:54 -0600
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.
_______________________________________________
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