因此,我一直在使用仪器中的NSZombiesEnabled和NSZombies进行调试。然而,当使用僵尸运行应用程序时,它似乎解决了我的问题。当我在仪器中运行没有NSZombiesEnabled或NSZombies的应用程序时,它崩溃了。你知道该怎么处理这件事吗?
所以问题是我发布了两次,但似乎找不到我在哪里做这件事。打开NSZombieEnabled不会有什么帮助,因为程序运行得很好,却没有告诉我发布到哪里了。
所以我想我知道它在哪里崩溃了,我有一个我正在创建的globalArray单例类:
extern NSString * const kClearDataSource;
@interface AHImageDataSource : NSObject
+ (AHImageDataSource *)sharedDataSource;
- (void) clearDataSource;
- (void) addObject:(id) object;
- (void) addObject:(id)object atIndex:(int) index;
- (int) count;
- (id) objectAtIndex:(int) index;
@end
NSString * const kClearDataSource = @"clearDataSource";
@interface AHImageDataSource()
{
NSMutableArray * imageDataSource_;
}
@property (nonatomic, retain) NSMutableArray * imageDataSource_;
@end
@implementation AHImageDataSource
@synthesize imageDataSource_;
+ (AHImageDataSource *)sharedDataSource {
static AHImageDataSource *_sharedClient = nil;
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
_sharedClient = [[self alloc] init];
});
return _sharedClient;
}
- (id)init {
self = [super init];
if (!self) {
return nil;
}
NSMutableArray * temp = [[NSMutableArray alloc] initWithCapacity:200];
self.imageDataSource_ = temp;
[temp release];
return self;
}
-(void) clearDataSource
{
if ([self.imageDataSource_ count] > 0){
[self.imageDataSource_ removeAllObjects];
}
}
- (void) addObject:(id) object
{
[self.imageDataSource_ addObject:object];
}
- (void) addObject:(id)object atIndex:(int) index
{
[self.imageDataSource_ insertObject:object atIndex:index];
}
- (int) count
{
return [self.imageDataSource_ count];
}
- (id) objectAtIndex:(int) index
{
if (index >= 0 && index < [self.imageDataSource_ count]){
return [self.imageDataSource_ objectAtIndex:index];
}
return nil;
}
- (void) dealloc
{
[super dealloc];
[imageDataSource_ release];
}
@end在代码的某一点上,我试图删除数组中的所有对象,然后在中添加一些内容。当这种情况发生时,崩溃就发生了。
这部分代码在第二次执行时崩溃:
NSArray *arr = [response valueForKey:@"data"];
if ([arr count] > 0){
[[AHImageDataSource sharedDataSource] clearDataSource];
}
for (NSDictionary * data in arr){
AHInstagramImageData * imgData = [[AHInstagramImageData alloc] initWithData:data];
[[AHImageDataSource sharedDataSource] addObject:imgData];
[imgData release];
}发布于 2012-05-22 08:16:49
你绝对不应该在你的-dealloc方法中先做[super dealloc]。它必须排在最后。
发布于 2012-05-22 05:27:57
转到产品->分析。显示的消息将为您提供解决方案或想法。
发布于 2012-05-22 05:36:22
当一个已释放的对象被发送消息时,你的应用程序就会崩溃。NSZombiesEnabled可以防止你的应用程序崩溃,因为它会保留所有释放的对象(因此会泄露所有内容)。当一个被释放的对象被发送一条消息(这通常会使你的应用崩溃)时,它会在控制台中打印一条消息。类似于“消息'bar‘发送到已释放的对象'foo'”(或类似的内容)的内容。它实际上并不会暂停你的应用程序的执行。
当你知道你的应用程序通常会崩溃的时候,检查控制台日志中类似上面的消息。
https://stackoverflow.com/questions/10692831
复制相似问题