Chetan
Chetan

Reputation: 47981

NSMutableArray releasing / destruction

The following code in my function (run in a loop) is causing my program to use more and more memory until it crashes. What am I doing wrong?

- (void) processTrackValues:(NSMutableArray*) tags {  
    NSImage* trackArt = [tags objectAtIndex:5];  
    NSMutableArray* tempArtArray = [[NSMutableArray alloc] init];  
    [tempArtArray addObject:trackArt];  
    [tempArtArray release];  
}

I also tried:

- (void) processTrackValues:(NSMutableArray*) tags {  
    NSImage* trackArt = [tags objectAtIndex:5];  
    NSMutableArray* tempArtArray = [[NSMutableArray alloc] init];  
    [tempArtArray addObject:trackArt];  
    [trackArt release];  
    [tempArtArray release];  
}

Edit: Here is more information on the surrounding code. I have also added more code to the sample for a bigger picture.

Upvotes: 1

Views: 492

Answers (2)

bbum
bbum

Reputation: 162712

The (now posted twice) method is nonsense. At the end of the method, the method has accomplished exactly nothing.

Post the real code.

In particular, how are you actually creating the NSImage instances? How do you know that this particular method is causing the bloat and eventual crash?

Upvotes: 2

Andy Bowskill
Andy Bowskill

Reputation: 1734

can you post the surrounding loop code to help get a bigger picture?

Do you allocate and release tempArtArray for every loop iteration? If so can you instead allocate it once outside of the loop and reuse it?

How are the trackArt objects created?

Upvotes: 0

Related Questions