0
我試圖建立一個NSInovcation系統使用performSelectorInBackground推出選擇到後臺線程: - ( - )到目前爲止,一切都運行在實例方法系統時是成功的,但我也想支持類的方法(+) 。我已經調整了我的代碼,爲這兩種類的類提供了invokeInBackgroundThread,除了一個問題外,其他所有的東西都可以工作。當類方法被調用時,我得到我的控制檯充斥着「autoreleased沒有池到位」的消息。不知道是什麼原因造成的。下面顯示了基於DDFoundation開源項目的代碼。NSInvocation的泄漏
@implementation NSObject (DDExtensions)
...
+ (id)invokeInBackgroundThread
{
DDInvocationGrabber *grabber = [DDInvocationGrabber invocationGrabber];
[grabber setInvocationThreadType:INVOCATION_BACKGROUND_THREAD];
return [grabber prepareWithInvocationTarget:self];
}
- (id)invokeInBackgroundThread
{
DDInvocationGrabber *grabber = [DDInvocationGrabber invocationGrabber];
[grabber setInvocationThreadType:INVOCATION_BACKGROUND_THREAD];
return [grabber prepareWithInvocationTarget:self];
}
...
...
- (void)forwardInvocation:(NSInvocation *)ioInvocation
{
[ioInvocation setTarget:[self target]];
[self setInvocation:ioInvocation];
if (_waitUntilDone == NO) {
[_invocation retainArguments];
}
if (_threadType == INVOCATION_MAIN_THREAD)
{
[_invocation performSelectorOnMainThread:@selector(invoke)
withObject:nil
waitUntilDone:_waitUntilDone];
} else {
[_invocation performSelectorInBackground:@selector(invoke)
withObject:nil];
}
}
...
+(void)doSomething;
[[className invokeOnBackgroundThread] doSomething];