• 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: Synthesize NSMutableString retain count question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Synthesize NSMutableString retain count question


  • Subject: Re: Synthesize NSMutableString retain count question
  • From: Jens Alfke <email@hidden>
  • Date: Wed, 3 Feb 2010 09:37:38 -0800


On Feb 3, 2010, at 3:55 AM, Philip Vallone wrote:

currentSection  = @"Some value";
The retain count goes to 1

This assigns a new value to the pointer variable 'currentSection'. It now points to the immutable string literal @"Some value".


However if I assign a value with
[currentSection setString:@"Some value"];
The retain count is still zero.

This tells the mutable string object that 'currentSection' currently points to, to replace its contents with the characters in the string @"Some value".


If you find the retain count is zero after this, it's probably because the value of 'currentSection' is nil, i.e. it doesn't point to any object. In that case the -setString: message is a no-op since messages to nil are ignored, and -retainCount will return zero because messages to nil always return 0/nil.

In general, it sounds as though you're unclear on the distinction between an object and a pointer to an object. It's the same as structs vs. pointers to structs in C, or for objects in C++; the difference is that Objective-C objects can only be referred to by pointers (you can't have a variable of type "NSString", only "NSString*".)

—Jens_______________________________________________

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


  • Follow-Ups:
    • Re: Synthesize NSMutableString retain count question
      • From: Philip Vallone <email@hidden>
References: 
 >Synthesize NSMutableString retain count question (From: Philip Vallone <email@hidden>)

  • Prev by Date: Re: Multithread communication
  • Next by Date: Re: Multithread communication
  • Previous by thread: Re: Synthesize NSMutableString retain count question
  • Next by thread: Re: Synthesize NSMutableString retain count question
  • Index(es):
    • Date
    • Thread