Ios NSOperationQueue泄漏?
我正在尝试使用NSOperationQueue在后台线程中执行一个方法,如下所示:Ios NSOperationQueue泄漏?,ios,multithreading,nsoperation,Ios,Multithreading,Nsoperation,我正在尝试使用NSOperationQueue在后台线程中执行一个方法,如下所示: NSOperationQueue *queue = [NSOperationQueue new]; NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(method)
object:nil];
[queue addOperation:operation];
[queue release];
[operation release];
问题是,analyzer说有一个泄漏存储在队列中
如何修复此问题?您是否正在释放
操作
对象?尝试添加autorelease
关键字
NSInvocationOperation *operation = [[[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(method)
object:nil] autorelease];
您是否正在释放
操作
对象?尝试添加autorelease
关键字
NSInvocationOperation *operation = [[[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(method)
object:nil] autorelease];
调用[MyClass new]与调用[[MyClass alloc]init]相同,它返回retainCount=1的对象。
因此,它应该在之后释放。调用[MyClass new]与调用[[MyClass alloc]init]相同,它返回retainCount=1的对象。
所以,应该在之后发布。只是想知道,您在方法“method”中做什么?您正在使用自动释放池吗?顺便说一句,用答案来帮助你。只是想知道,你在你的方法“方法”里面做什么?您正在使用自动释放池吗?顺便说一句,请使用答案来帮助您。我已经发布了操作,这是我发布的代码中的第四行。我正在泄漏队列吗?我已经在释放操作,这是我发布的代码中的第四行。我是在泄漏队列吗?上面的代码如何?analyzer警告消失了,但我只想确保我做的是正确的事情!上面的代码如何,analyzer警告消失了,但我只想确保我做的是正确的事情!