Re: More memory management questions
Re: More memory management questions
- Subject: Re: More memory management questions
- From: Sherm Pendley <email@hidden>
- Date: Sat, 2 Mar 2002 01:29:48 -0500
On Friday, March 1, 2002, at 08:37 PM, David Newberry wrote:
My question here is, if I do something like this:
NSString *string = [NSMutableString stringWithString:@"temp"];
Have I "allocated" this object?
No. "Allocate, copy, or retain" means calling "alloc," "copy," or
"retain" methods. These methods must be "balanced" by a corresponding
"release" or "autorelease" when the object is to be disposed of.
If not, should it be treated as a received object (below)?
Yes.
This sounds like (as far as my understanding goes), you should treat
received objects as though they were sent an autorelease message before
being returned. Is this a reasonable assumption, at least for
understanding the object's behavior?
Yes.
"* Use retain and autorelease when needed to prevent an object
from being invalidated as a normal side-effect of a message."
My question here is: If you have an allocated object that hasn't
received any retain or [auto]release messages, what will it do? Stick
around forever? or be removed with the next NSAutoreleasePool call?
It will take up memory until it's either released or autoreleased.
sherm--
_______________________________________________
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.