【发布时间】:2013-01-14 23:33:49
【问题描述】:
我在Xcode 4.5 的 Mac OS X 应用程序上运行了仪器。我有两个 NSOperation 依赖子类,我在将它们添加到进程队列后忘记释放它们。所以我在将它们添加到队列后就释放了它们。该应用程序运行良好。我在 Instruments 上对其进行了分析,但它崩溃了。
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 在我想释放最后一个操作时崩溃(参见代码),但应用程序似乎运行良好。
有人有建议吗?是 Instruments 的错误还是我的代码有问题?
【问题讨论】:
-
您怎么知道是您的应用程序导致仪器崩溃?
-
当我在发布的代码中注释最后一行时,Instruments 运行良好。它因为分段错误而崩溃。
-
可能是conversionOp类里面的东西,你覆盖dealloc吗?
-
我重写了 dealloc 并且只释放了一个字符串对象。但它不应该改变任何东西。当您在进程队列中添加一个操作时,它会被保留。并且该应用仅在 Intruments 中崩溃。
标签: objective-c crash instruments nsoperation