• 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: newbie questions on NSString* as a class attribute
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: newbie questions on NSString* as a class attribute


  • Subject: Re: newbie questions on NSString* as a class attribute
  • From: Mike Abdullah <email@hidden>
  • Date: Wed, 22 Apr 2009 10:06:56 +0100


On 22 Apr 2009, at 02:15, Andrew Farmer wrote:

On 21 Apr 09, at 17:53, Wayne Shao wrote:
Let's say that I have a member variable NSString* logFilePath, I do init
in the initWith.... method as
logFilePath = [[some_other_path stringByAppendingPathComponent:@"log.txt"]
copy];


The question is, if I do not call copy, is it true that logFilePath could be
subject to be GC'ed?

Are you using garbage collection or not?

If you ARE using garbage collection, the copy is unnecessary. So long as the value is reachable through strong references (which logFilePath is, so long as the object itself is reachable), it will not be collected.

If you ARE NOT using garbage collection, you should be retaining this value rather than copying it. See the memory management programming guide [1] for details.

[1]: http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/index.html

To be fair, NSString's immutable nature does make -copy perfectly acceptable (and I would say desirable in many cases) as it ends up doing the same as -retain.


Mike.

_______________________________________________

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: 
 >newbie questions on NSString* as a class attribute (From: Wayne Shao <email@hidden>)
 >Re: newbie questions on NSString* as a class attribute (From: Andrew Farmer <email@hidden>)

  • Prev by Date: Re: MDItemCopyAttribute and kMDItemFinderComment
  • Next by Date: Re: Core Data Fetches + Transient Properties + NSPredicateEditor = Sadness
  • Previous by thread: Re: newbie questions on NSString* as a class attribute
  • Next by thread: Modal dialog over modal dialog in Cocoa
  • Index(es):
    • Date
    • Thread