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