So, I debugged myself like crazy using NSZombiesEnabled and NSZombies in tools. However, when running the application using zombies, it seems to solve my problem. When I run the application without NSZombiesEnabled or NSZombies in tools, it crashes. Any idea on how to deal with this?
So the problem is that I release something twice, but cannot find where I do it. Enabling NSZombieEnabled will not help, because the program works fine without telling me where I finished the release.
So, I think I know where it crashes, I have this globalArray Singleton class that I create:
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
at one point in the code, I'm trying to delete all the objects in the array, and then add some things. When this happens, a failure has occurred.
This part of the code crashes a second time:
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]; }
source share