Not understanding 'Possible leak of an object' error
346 - NSFileManager *fileManager = [[NSFileManager alloc] init];
347 - [fileManager removeItemAtPath:[mediaSource.newMediaToDelete objectAtIndex:i] error:nil];
348 - [fileManager release];
The error points towards line 348 and says:
'Potential leak of an object allocated on line 347'
I don't开发者_StackOverflow社区 understand this, obviously line 347 isn't an allocation, and the allocation on line 346 is already released.
Avoid using the 'new' or 'create' in your own method names (unless they return objects that are not autoreleased I guess). It confuses the static analyser. I've had this issue and found it went away when I changed my method name.
Update: I see Bavarious has already noted this in the comments.
May be in NSArray mediaSource.newMediaToDelete objects are not autorelease?
I tried the following code and did not get any warning:
NSInteger i = 0;
NSArray *ax = [NSArray arrayWithObjects:@"a",@"b",@"c",nil];
NSFileManager *fileManager = [[NSFileManager alloc] init];
[fileManager removeItemAtPath:[ax objectAtIndex:i] error:nil];
[fileManager release];
So it must be with returned mediaSource.newMediaToDelete object...
try a var assignemnt like:
x = [mediaSource.newMediaToDelete objectAtIndex:i];
and it should show there...
Have you tried to click on the error message itself? Those arrows which show you the path of your problem are sometimes very useful. I guess it is the mediaSource or newmediaToDelete object which causes the message.
精彩评论