Re: More memory management questions
Re: More memory management questions
- Subject: Re: More memory management questions
- From: "Joshua D. Orr" <email@hidden>
- Date: Sat, 2 Mar 2002 00:03:25 -0700
On Friday, March 1, 2002, at 11:09 PM, cocoa-dev-
email@hidden wrote:
Message: 1
Date: Fri, 1 Mar 2002 17:37:34 -0800
Subject: More memory management questions
From: David Newberry <email@hidden>
To: email@hidden
My question here is, if I do something like this:
NSString *string = [NSMutableString stringWithString:@"temp"];
Have I "allocated" this object? If not, should it be treated as a
received
object (below)?
No you have not, this will return an autoreleased NSString. If you
release this object without first retaining it you will resive an auto
release pool error. This means the pool tried to release something that
was already released and it will crash you app.
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?
When you allocate an object like:
[[NSString alloc] initWithString:@""]
It will stick around for ever until you release it or until you app
quits. It will not release with the next auto release pool since it was
not sent a [theObject autorelease] message...
Lastly: I'm experimenting with getting my memory management right, and
am
(predictably -- I am a newbie to Cocoa) getting exceptions in the
NSAutoreleasePool method. Is there any way for me to know what object it
is that causes the exception?
This means that you released an auto release object that you did not
retain first. When the pool tried to release the object, it was already
released (no longer in memory).
Thanks again.
Your welcome!
_______________________________________________
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.