簡體   English   中英

NSZombieEnabled阻止我的應用程序崩潰

[英]NSZombieEnabled prevents my app from crashing

因此,我一直在使用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];
                 }

你絕對不應該在-dealloc方法中首先執行[super dealloc] 它必須到最后

去產品 - >分析。 顯示的消息將為您提供解決方案或想法。

當已解除分配的對象發送消息時,您的應用程序崩潰。 NSZombiesEnabled可以防止您的應用程序崩潰,因為它會保留所有已解除分配的對象(從而泄漏所有內容)。 當解除分配的對象發送消息時(通常會使應用程序崩潰),它將在控制台中打印消息。 “消息'欄'發送到解除分配對象'foo'”(或類似的東西)的影響。 它實際上並沒有暫停您的應用程序的執行。

當您通過了解應用程序通常崩潰的位置時,請檢查控制台日志中是否有類似上述消息的消息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM