Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory leak.




On Aug 30, 2005, at 9:59 AM, Brian O'Brien wrote:

Hi I am writing an ObjectiveC framework.
A user of my framework is complaining of a memory leak.
There is inded a memory leak..

This is a Cocoa related question more then a Objective-C question better to ask on Apple's Cocoa developers list.

- (NSArray *) readFiles:(NSArray *)fileNames
{    
    int n = [fileNames count];
    NSMutableArray *ret = [NSMutableArray arrayWithCapacity:n];
    for (int i=0; i < n; i++)
    {
        Image * img = [self readFile:[fileNames objectAtIndex:i]];
        if (img != nil)
            [ret addObject:img];
    }
    return ret;
}

I was told that the NSMutableArray would actually be responsible
for the destruction of the objects it contained... Perhaps I am misinformed? 

NSArray will send a retain to an object when that object is added to the array. NSArray will send a release when the object is removed from the array. If an NSArray gets deallocate all objects are implicitly removed hence all contained objects are the time of dealloc get a release message.

As a work around I have suggested that the user iterate through the NSMutableArray
and deallocate the images then deallocate the NSMutableArray... 

The issue is not with NSArray but with your code, in this case likely something in readFile: that isn't balancing retain (or implicit retain) with a release or autorelease as needed.

We would have to see what readFile: is doing.

-Shawn
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/objc-language/email@hidden

This email sent to email@hidden

References: 
 >Memory leak. (From: "Brian O'Brien" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.