Re: Solving memory leaks
Re: Solving memory leaks
- Subject: Re: Solving memory leaks
- From: Quincey Morris <email@hidden>
- Date: Sat, 27 Mar 2010 18:14:50 -0700
On Mar 27, 2010, at 16:51, Noah Desch wrote:
> If you are *not* using getters and setters but instead have myFields declared as:
>
> @interface MyClass
> {
> NSMutableDictionary *myFields;
> }
>
> and you use the above line of code, and subsequently release myFields in your dealloc method.... this would *not* be a memory leak, correct?
Correct (except that the 'self.' syntax won't work.) The OP had exactly the code pattern you describe:
...
if (myFields == nil)
myFields = [[NSMutableArray alloc] init];
...
- (void) dealloc {
[myFields release];
...
}
(The OP called it just 'fields'.) That's not a memory leak -- in the first part, the MyClass object owns the array it creates (once), and it relinquishes ownership in its 'dealloc' (once). There can only be a leak for one of 3 reasons:
1. Some other piece of code assigns a new value to 'myFields' without releasing the old value.
2. Some other piece of code retains 'myFields', but never releases it.
3. The MyClass object is itself leaked, so its dealloc is never called.
_______________________________________________
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