Re: best way to "reset" values
Re: best way to "reset" values
- Subject: Re: best way to "reset" values
- From: Shawn Erickson <email@hidden>
- Date: Sat, 01 Sep 2007 09:15:53 -0700
On Sep 1, 2007, at 9:00 AM, Daniel Child wrote:
Hi All,
As I grapple with the whole memory management issue, a question I
haven't seen explicitly addressed is now to reset ivars to default
(empty) values.
As far as I understand, if I use
[self setMyString: @""];
then the @"" is a constant that can never be freed. Or is that OK?
(I need to reset the value often, and don't want to leak memory.)
Look at it from the point of view of the Cocoa memory contract "rules".
Does " @"" " contain the words alloc, copy, new, etc.? Nope... so you
don't have to worry about memory managing that object. It is also
true that it is an immutable string (like NSString is) the rest is,
in reality, an implementation detail.
Also, is the approach different if the ivar is a collection (set,
array, dictionary...)?
Read the memory management rule... it is hard to answer your question
in the abstract and do it as well as the document I referenced
earlier does.
-Shawn
_______________________________________________
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