Re: Making an object release itself?
Re: Making an object release itself?
- Subject: Re: Making an object release itself?
- From: Jean-Daniel Dupas <email@hidden>
- Date: Tue, 6 Jan 2009 09:35:26 +0100
Le 1 janv. 09 à 20:00, Jim Correia a écrit :
On Dec 30, 2008, at 10:28 PM, Jacob Rhoden wrote:
Im still learning cocoa, so I have a question about if this is a
good idea or a crazy noob mistake. Given the following code can I
alter it so that postreader auto releases itself?
[...]
I'm thinking PostReader class could have a static function that
initialises a new PostReader object, tells it to start the work,
and then do a [self release] after it has called the callback
function 'postsRead';
In a retain/release world, having the helper object own itself, and
remove that reference when its async work is complete (and it has
posted the results somewhere) is generally OK.
If you intend this code to work in a GC environment though, you must
make sure your helper object is rooted, or some other object keeps a
strong reference to it, until the async work is complete, otherwise
it will be collected.
Or you can use -[NSGarbageCollector disableCollectorForPointer:/
enableCollectorForPointer:], or CFRetain/CFRelease functions (that
prevent collection too).
Jim
_______________________________________________
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
_______________________________________________
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