• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: best way to "reset" values
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >best way to "reset" values (From: Daniel Child <email@hidden>)

  • Prev by Date: Re: NSBezierPath append CGGlyph
  • Next by Date: Re: many messages between threads
  • Previous by thread: best way to "reset" values
  • Next by thread: Re: core data app questions - help!
  • Index(es):
    • Date
    • Thread