why do I need this autorelease after [NSMutableArray array] to avoid a memory leak?
That is Instruments told me there was a leak. By putting the autorelease in it solved it, however I'm not sure why this would be required. The "array" method wasn't like an INIT or COPY etc...
@interface Weekend : NSObject {
NSMutableArray* _events;
}
@property (nonatomic, retain) NSMutableArray* events;
@end
@implementation Weekend
@synthesize events = _events;
- (id)init {
if (self == [super init])
{
self.events = [[NSMutableArray array] autorelease]; // WHY IS THIS AUTORELEASE REQUIRED
}
return self;
}
- (void) dealloc {
[_events release]; _events = nil;
[super dealloc];
}
@end
NOTE: This is what I see in Intruments when I take autorelease out (and after I changed the "if (self == [super init])" to "if ((self = [super init]))"
# Category Event Code Location
0 __NSArrayM Malloc at the [NSMutableArray array] point
1 __NSArrayM Autorelease at the [NSMutableArray array] point
2 __NSArrayM Retain at the @synthesize events = _events; point of the code
3 __NSArrayM Release QuartzCore - CA:Transaction::observer_callback(__CF........)
(from main.m:14 - "int retVal = UIApplicationMain(argc, argv, nil, nil);")