我已经试着修复这起事故将近一周了.应用程序崩溃,没有任何异常或堆栈跟踪.在僵尸模式下运行仪器时,应用程序不会以任何方式崩溃.
我有一个在不同线程上被调用的方法.
[self.mutableArray removeAllObjects];
具有
dispatch_async(dispatch_get_main_queue(), ^{
[self.searchResult removeAllObjects];
});
我认为这可能是时间问题,所以我try 同步它,但它仍然崩溃:
@synchronized(self)
{
[self.searchResult removeAllObjects];
}
这是密码
- (void)populateItems
{
// Cancel if already exists
[self.searchThread cancel];
self.searchThread = [[NSThread alloc] initWithTarget:self
selector:@selector(populateItemsinBackground)
object:nil];
[self.searchThread start];
}
- (void)populateItemsinBackground
{
@autoreleasepool
{
if ([[NSThread currentThread] isCancelled])
[NSThread exit];
[self.mutableArray removeAllObjects];
// Populate data here into mutable array
for (loop here)
{
if ([[NSThread currentThread] isCancelled])
[NSThread exit];
// Add items to mutableArray
}
}
}
Is this problem 具有 NSMutableArray not being thread-safe?