NSZombieEnabled阻止我的应用程序崩溃

时间:2012-05-21 21:24:36

标签: iphone objective-c ios ipad

所以我一直在使用NSZombiesEnabled和NSZombies在仪器中调试疯子。但是,当使用僵尸运行应用程序时,它似乎解决了我的问题。当我在没有NSZombiesEnabled或NSZombies的应用程序中运行应用程序时,它会崩溃。关于如何处理这个的任何想法?

所以问题是我发布了两次,但似乎无法找到我在做这个的地方。打开NSZombieEnabled无济于事,因为程序运行良好而没有告诉我我在哪里过度发布。

所以我觉得我知道崩溃的地方,我正在创建这个globalArray Singleton类:

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];
                 }

3 个答案:

答案 0 :(得分:3)

您绝对不应该在[super dealloc]方法中执行-dealloc 。它必须最后

答案 1 :(得分:1)

Go go Product - &gt;分析。显示的消息将为您提供解决方案或想法。

答案 2 :(得分:1)

当已解除分配的对象发送消息时,您的应用程序崩溃。 NSZombiesEnabled可以防止您的应用程序崩溃,因为它会保留所有已解除分配的对象(从而泄漏所有内容)。当解除分配的对象发送消息时(通常会使应用程序崩溃),它将在控制台中打印消息。 “消息'栏'发送到解除分配对象'foo'”(或类似的东西)的影响。它实际上并没有暂停您的应用程序的执行。

如果您已经通过了解应用程序通常崩溃的位置,请检查控制台日志中是否有与上述类似的消息。