Objective c NSOperation子类释放使仪器崩溃

Objective c NSOperation子类释放使仪器崩溃,objective-c,crash,instruments,nsoperation,Objective C,Crash,Instruments,Nsoperation,我在Mac OS X应用程序上运行了Xcode 4.5中的仪器。我有两个NSOperation依赖子类,在将它们添加到进程队列中后忘记释放它们。因此,我在将它们添加到队列中之后才释放了它们。这个应用程序工作得很好。我在仪器上描绘了它,但它崩溃了 processQueue = [[NSOperationQueue alloc] init]; NSUInteger max = [[NSUserDefaults standardUserDefaults] integerForKey:@"jobsKey

我在Mac OS X应用程序上运行了
Xcode 4.5
中的仪器。我有两个
NSOperation
依赖子类,在将它们添加到进程队列中后忘记释放它们。因此,我在将它们添加到队列中之后才释放了它们。这个应用程序工作得很好。我在仪器上描绘了它,但它崩溃了

processQueue = [[NSOperationQueue alloc] init];
NSUInteger max = [[NSUserDefaults standardUserDefaults] integerForKey:@"jobsKey"];
processQueue.maxConcurrentOperationCount = max;
GeocacheDownloadOperation * downloadOp = [[GeocacheDownloadOperation alloc]  initWithGeocache:cache InPath:directoryPath withDelegate:self];        
GeocacheJPGConversionOperation * conversionOp = [[GeocacheJPGConversionOperation alloc] initWithCache:cache WithPath:directoryPath WithDelegate:self];

[conversionOp addDependency:downloadOp];     
[processQueue addOperation:downloadOp];
[processQueue addOperation:conversionOp];

[downloadOp release];
[conversionOp release]; //This line makes Instruments crash
Instruments
当我想释放最后一个操作时崩溃(请参见on code),但应用程序似乎工作得很好


有人有什么建议吗?这是一个Instruments bug还是我的代码有问题?

我猜conversionOp在解除分配时会释放每个依赖项(在本例中是downloadOp)。因此,在两个操作完成后调用[conversionOp release](这取决于线程的调度方式),因此您过度释放了downloadOp。

我发现了错误,但我无法解释为什么它单独工作,而不是在仪器中工作。我在
NSOperation
子类中使用了一个released变量,我在NSOperation子类的
dealloc
函数中第二次释放了该变量。现在,我不再覆盖
[super dealloc]
中的
NSOperation
子类,它可以正常工作。

你怎么知道是你的应用程序让instruments崩溃了?当我评论发布的代码中的最后一行时,instruments工作得很好。它崩溃是因为一个分段错误。它可能是conversionOp类中的某个东西,您是否重写了dealloc?我重写了dealloc,只释放了一个string对象。但它不应该改变任何事情。在流程队列中添加一个操作时,它将被保留。应用程序只会在设备中崩溃。我尝试先删除
[downloadOp release]
。该应用程序仍在仪器内部崩溃。然后我删除了第二个版本,Instruments可以工作,但我在
GeocacheDownloadOperation
GeocacheJPGConversionOperation
中有漏洞……您能否同时显示GeocacheDownloadOperation和GeocacheJPGConversionOperation类?抱歉,我不允许发布它:(