Thanks mmalc, that clears things up for me.

On 05/02/2009, at 8:08 PM, mmalc Crawford wrote:


On Feb 4, 2009, at 10:01 PM, Kiel Gillard wrote:

I'm confused as to why else the memory would be leaking? Can you please identify my error?

The error is in your explanation.

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.

This is not a memory leak "because the property definition tells the compiler the methods it synthesizes should retain the value"; it is a leak because you're not abiding by the memory management rules. You're creating an object you own (alloc), and not relinquishing ownership. (See <http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/MemoryManagementRules.html > for full details.)

There are several ways to remedy the problem; the overall best practice approach is:

NSString *aString = [[NSString alloc] init];
self.name = aString;
[aString release];


I suggest that the code quoted above will yield a memory leak because the NSString instance allocated will have a retain count of two

Explaining memory management at this level in terms of retain counts is a leap down the wrong path.

mmalc

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/kiel.gillard%40gmail.com

This email sent to kiel.gill...@gmail.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to