Reputation: 47981
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.
trackArt
is an NSImage
pointer to one of the arguments to this function.NSImage
object that trackArt
points to is created outside of this function.tempArtArray
each iteration of the loop (since the function is called for each iteration of the loop)Upvotes: 1
Views: 492
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
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