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 <stephen.but...@gmail.com
> wrote:

> On Tue, Dec 28, 2010 at 12:18 AM, ico <jche...@gmail.com> 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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to