Reputation: 37495
I have a class that's a subclass of NSOperation (actually a subclass of ASIHTTPRequest, which is a subclass of NSOperation).
Instruments is reporting a memory leak at __NSOperationInternal, with this call stack:
0 libSystem.B.dylib calloc
1 libobjc.A.dylib _internal_class_createInstanceFromZone
2 libobjc.A.dylib class_createInstance
3 CoreFoundation +[NSObject(NSObject) allocWithZone:]
4 CoreFoundation +[NSObject(NSObject) alloc]
5 CoreFoundation +[NSObject(NSObject) new]
6 Foundation -[NSOperation init]
7 MyApp -[JSONRequest init] JSONRequest.m:26
JSONRequest's init and dealloc look like this:
- (id)init
{
if ((self = [super init]))
{
[self setDidFinishSelector:@selector(JSONFinished:)];
[self setDidFailSelector:@selector(JSONLoadFailed:)];
}
return self;
}
- (void)dealloc {
[super setDelegate:nil];
[super dealloc];
}
I can't see an error in my code anywhere that could cause this. Is this likely to be a false leak, or does anyone have an idea what could be wrong with the code? (Are there any guidelines for telling if an leak reported by instruments is false or not?)
This is the only leak being reported (ie. none of the properties on the objects are being leaked) but this leak is being reported multiple times during a run of my application.
Upvotes: 3
Views: 665
Reputation: 37495
I managed to get to the bottom of this eventually.
It turned out that I was accidentally calling [super init] twice in some cases, apparently resulting in an object that [NSOperation init] allocates being leaked.
Upvotes: 2