-(void)invokeMethod
{
NSMethodSignature * sig = [[source class] instanceMethodSignatureForSelector:@selector(mySelector:)];
NSInvocation * invocation = [NSInvocation invocationWithMethodSignature:sig];
[invocation setTarget:myTarget];
[invocation setSelector:@selector(mySelector:)];
MySubClassOfNSInvocationOperation * command = [[[MySubClassOfNSInvocationOperation alloc] initWithInvocation:invocation] autorelease];
//setArgument retains command
[invocation setArgument:&command atIndex:2];
//addOperation retains command until the selector is finished executing
[operationQueue addOperation:command];
}
-(void)mySelector:(MySubClassOfNSInvocation*)command
{
//Do stuff
}
I don't know exactly what is happening, but NSInvocation
& MySubClassOfNSInvocationOperation
are leaking
When I remove the line:
[invocation setArgument:&command atIndex:2];
It doesn't leak, so some kind of problem with passing command as an argument.