• 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: Kiel Gillard <email@hidden>
  • Date: Thu, 5 Feb 2009 16:10:13 +1100

Hi Devraj,

If you have declared and synthesized a property:
@property (retain, nonatomic) NSString *name;

...then any value assigned to name will retain it. Therefore, to initialise it, you could do something like:
self.name = [NSString string];


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.

Hope this helps,

Kiel

On 05/02/2009, at 3:54 PM, Devraj Mukherjee wrote:

Hi all,

I have a few classes that form the domain logic of my application and
comprise of objects of NSNumber, NSDate, NSString. I initialize these
with new objects in the init message of each of these classes.

These properties are defined using the @property (nonatomic, retain)
and @synthesize directives.

When I create objects of these Classes and replace these other values
(objects), my app seems to leak memory (according to Instruments)
specially when working with NSDates. Is there a trick that I should be
looking for when using @property and @synthesize or should I actually
be writing my own setters and getters to handle these properly.

Thanks.

--
"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

_______________________________________________

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: Chris Suter <email@hidden>
References: 
 >Memory management question in Objective-C 2.0 @property notation (From: Devraj Mukherjee <email@hidden>)

  • Prev by Date: Re: Confused about NSTrackingAreas with autoscroll
  • Next by Date: Re: Memory management question in Objective-C 2.0 @property notation
  • Previous by thread: 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