gpt4 book ai didi

iphone - NSZombieEnabled 防止我的​​应用程序崩溃

转载 作者:可可西里 更新时间:2023-11-01 05:38:10 26 4
gpt4 key购买 nike

所以我一直在像疯子一样使用 Instruments 中的 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] first。它必须最后

关于iphone - NSZombieEnabled 防止我的​​应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10692831/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com