• 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: Memory management question in Objective-C 2.0 @property notation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory management question in Objective-C 2.0 @property notation


  • Subject: Re: Memory management question in Objective-C 2.0 @property notation
  • From: Devraj Mukherjee <email@hidden>
  • Date: Thu, 5 Feb 2009 19:21:56 +1100

Thanks again both of you.

assuming that I do self.name = [NSString string] and since it the
NSString helper message, I shouldn't have to release that in my
dealloc implementation.

Or am I understanding this incorrectly.

On Thu, Feb 5, 2009 at 5:01 PM, Kiel Gillard <email@hidden> wrote:
> On 05/02/2009, at 4:20 PM, Chris Suter wrote:
>
> On Thu, Feb 5, 2009 at 4:10 PM, Kiel Gillard <email@hidden> wrote:
>
> However, doing this will yield a memory leak:
>
> self.name = [[NSString alloc] init];
>
> ...because the property definition tells the compiler the methods it
>
> synthesizes should retain the value.
>
> You're right that it will leak in that case but you've given the wrong
> reason as to why. Memory management rules are covered by Apple's
> documentation.
>
> Regards,
>
> Chris
>
> Thanks for your reply, Chris.
> I suggest that the code quoted above will yield a memory leak because the
> NSString instance allocated will have a retain count of two after the
> setName: message has be sent to self. To correct this error, I suggest that
> the code should read:
> self.name = [[[NSString alloc] init] autorelease];
> Under the heading of "Setter Semantics"
> of <http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_5_section_3.html#//apple_ref/doc/uid/TP30001163-CH17-SW2>,
> I can see that Apple's documentation clearly states that the implementation
> of a property declared with a retain attribute will send a retain message to
> the value given in the right hand side of the assignment.
> I'm confused as to why else the memory would be leaking? Can you please
> identify my error?
> Thanks,
> Kiel
>



--
"The secret impresses no-one, the trick you use it for is everything"
- Alfred Borden (The Prestiege)
_______________________________________________

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: Memory management question in Objective-C 2.0 @property notation
      • From: Bryan Henry <email@hidden>
    • Re: Memory management question in Objective-C 2.0 @property notation
      • From: mmalc Crawford <email@hidden>
References: 
 >Memory management question in Objective-C 2.0 @property notation (From: Devraj Mukherjee <email@hidden>)
 >Re: Memory management question in Objective-C 2.0 @property notation (From: Kiel Gillard <email@hidden>)
 >Re: Memory management question in Objective-C 2.0 @property notation (From: Chris Suter <email@hidden>)
 >Re: Memory management question in Objective-C 2.0 @property notation (From: Kiel Gillard <email@hidden>)

  • Prev by Date: Re: Memory management question in Objective-C 2.0 @property notation
  • Next by Date: Re: Open OtherApp just behind MyApp
  • Previous by thread: Re: Memory management question in Objective-C 2.0 @property notation
  • Next by thread: Re: Memory management question in Objective-C 2.0 @property notation
  • Index(es):
    • Date
    • Thread