Re: Memory allocation questions
Re: Memory allocation questions
- Subject: Re: Memory allocation questions
- From: Roarke Lynch <email@hidden>
- Date: Fri, 2 Jan 1970 07:18:49 -0500
- (void)setMainSprocket:(Sprocket *)newSprocket
{
[mainSprocket autorelease];
mainSprocket = [newSprocket retain]; /* Claim the new Sprocket. */
return;
}
You could,
Caveat. You could not.
I don't know why they choose to do it that way
For newSprocket might be the same object as mainSprocket, and it might
have a retain count of one, in which case you'd dealloc it first and
use afterwards, with all the potential havoc.
Even if mainSprocket and newSprocket are the same object, this
could should not cause problems. By autoreleaseing, not releasing,
mainSprocket, it might not get dealloc'd, An object does not get
dealloc'd until it's reference count is zero. If they are the same
object, at the end of the eventLoop, it's ref count will remain the the
same as before this method was called.
Roarke Lynch
-------------------------------
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.