抱歉...羞耻- 我没有运行调试模式,所以错误出现在错误的行上。在调试模式下,并显示正确的行,错误是一个简单的“不要访问超出其边界的数组”-错误(错别字 - 我指的是一个数组,但访问的是另一个数组)
当我从另一个线程清空 NSMutableArray 时,为什么访问 NSMutableArray 的计数会产生 SIGABRT?我认为@synchronized 应该像它的名字所暗示的那样做?
NSMutableArray *sourceImageRepArray;
...
@synchronized(self)
{
NSLog(@"singleton 1 %p", self);
unsigned long count = sourceImageRepArray.count; //SIGABRT here!
...
不知道你想让我分享多少额外的代码......这是触发它的代码:
@synchronized([Singleton sharedSingleton])
{
NSLog(@"singleton 2 %p", [Singleton sharedSingleton]);
int i, n;
n = [filenames count];
for(i=0; i<n; i++){
ImageRep *item = [[ImageRep alloc] init];
[item setPath:[filenames objectAtIndex:i]];
[[Singleton sharedSingleton].targetImageRepArray insertObject:item atIndex: [targetImageBrowser indexAtLocationOfDroppedItem]];
[item release];
[[Singleton sharedSingleton] removeImageRepFromArray:[Singleton sharedSingleton].sourceImageRepArray withPath:[filenames objectAtIndex:i]];
}
}
单例 1 == 单例 2:
2011-02-08 07:22:03.265 Crash[60001:5d03] singleton 1 0x200047680
2011-02-08 07:22:03.433 Crash[60001:a0f] singleton 2 0x200047680
- 为什么不同步?!还有什么可能发生的?