ico <mailto:jche...@gmail.com> wrote (Tuesday, December 28, 2010 11:18 PM +0800):

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.

As a general rule, I would avoid releasing |self| since (conceptually) an object does not own itself.

The answer to your question is, I think, simple: Follow good memory management procedures. Retain objects until you no longer need to reference them, and then release them.

Having said that, if your connectionDidFinishLoading: does all of the post processing, and after it returns there are no more references to the DataHandler object, then it would be appropriate to release/autorelease it in the callback.

Using autorelease would be a tad less scary because you'd know that |self| will continue to exist until after connectionDidFinishLoading: returns. With -release you run the (theoretical) risk that you could destroy |self| before you return. In reality, the asynchronous URL loader framework must retain your object until after the callbacks have been made (else how could safely invoke the callback?). So I'm sure it's safe to call -release or -autorelease.
--
James Bucanek

_______________________________________________

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