我正在尝试使用如下所示的NSOperationQueue在后台线程中执行方法:
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(method)
object:nil];
[queue addOperation:operation];
[queue release];
[operation release];问题是,分析器说有一个存储在队列中的泄漏。
我该如何解决这个问题呢?
发布于 2011-12-29 03:58:44
调用MyClass和调用[MyClass alloc ]是一样的,它返回的是retainCount = 1的object,所以应该在之后释放。
发布于 2011-12-29 03:21:37
你要发布operation object吗?尝试添加autorelease关键字
NSInvocationOperation *operation = [[[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(method)
object:nil] autorelease];发布于 2011-12-29 18:42:50
只是想知道,你在你的方法“方法”里面做了什么?你在使用NSAutoreleasePool吗?顺便说一下,使用this answer可以帮助您解决问题。
https://stackoverflow.com/questions/8660239
复制相似问题