Re: Do I need to relase @"string" ??
Re: Do I need to relase @"string" ??
- Subject: Re: Do I need to relase @"string" ??
- From: Bryan Henry <email@hidden>
- Date: Mon, 02 Mar 2009 18:47:53 -0500
Assuming that the setter is copying the value passed in (which it
should be, considering setCurrentMiles: should accept a single
NSString*), yes James, you should release currentMiles in your -
(void)dealloc implementation for that class. The release won't affect
the constant strings, but to be correct and prevent leaks in the case
where setCurrentMiles: may be passed an non-constant string, you need
to do that.
Quick note:
If you're using properties and synthesized accessors, NSString*
properties should be copy and not retain unless you have a good reason
otherwise.
If you're writing the setter and getter yourself, use -copy and not -
retain when its an NSString*.
The reason being that, for immutable objects, -copy will be
effectively the same as -retain...but if setCurrentMiles: is passed an
NSMutableString* it actually creates a new immutable instance.
Bryan
On Mar 2, 2009, at 4:21 PM, Dave DeLong wrote:
My understanding was that he was referring to the setter in his
AppDelegate class. Since the only thing (apparently) getting passed
into the setter was an NSConstantString, it would seem that he
wouldn't need to worry about releasing that property. (Assuming the
setter was retaining it)
Dave
On Mar 2, 2009, at 2:18 PM, Kyle Sluder wrote:
On Mon, Mar 2, 2009 at 3:58 PM, James Cicenia <email@hidden>
wrote:
DO I HAVE TO WORRY ABOUT RELEASING currentMiles somewhere?
YOU MIGHT WANT TO WORRY about releasing your Shift key. ;-)
Just follow the memory management guides. You didn't use +alloc,
+new, or -copy to make the object, so you don't own it. Therefore
you
don't have to worry about releasing it.
--Kyle Sluder
_______________________________________________
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