So here's the beef. I'm trying to create a class variable that's a mutable array. I add some conditions to the init and dealloc methods that see if the the array isn't a nil value and init it and dealloc it accordingly. However, when I release the array it doesn't actually seem to be releasing it. I ran the retain count through NSLog to look at it, and sure enough, before and after the release its count remains at 1. Is this a memory leak or is this behavior by design? This is my isolated code.
HelloWorldScene.m
- (void)init{
fooObject *foo1 = [fooObject new];
fooObject *foo2 = [fooObject new];
[foo1 release];
[foo2 release];
}
@end
@implementation fooObject
static NSMutableArray *fooArray;
- (id)init{
if (self == [super init]) {
if (!fooArray) {
fooArray = [NSMutableArray new];
NSNumber *fooNum = [NSNumber numberWithInt:0];
for (int x = 0; x < 4; x++) {
[fooArray addObject:fooNum];
}
}
}
return self;
}
- (void)dealloc{
if (fooArray) {
NSLog(@"retainCount1: %i", [fooArray retainCount]);
[fooArray release];
NSLog(@"retainCount2: %i", [fooArray retainCount]);
fooArray = nil;
}
[super dealloc];
}
@end