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] ini开发者_Python百科t];
[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 anNSImage
pointer to one of the arguments to this function.- The
NSImage
object thattrackArt
points to is created outside of this function. - I am allocating and releasing
tempArtArray
each iteration of the loop (since the function is called for each iteration of the loop)
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?
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?
精彩评论