Re: Memory management about async object
Re: Memory management about async object
- Subject: Re: Memory management about async object
- From: James Bucanek <email@hidden>
- Date: Tue, 28 Dec 2010 08:36:41 -0700
ico <mailto:email@hidden> 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 (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