I have a class with a NSMutableArray* declared in the header file. I am not using a property for it. In the constructor I have:
-(id) initWithWidthint)_width Heightint)_height Frictionfloat)_friction TimeDeltafloat)_timeDelta {
if(self = [super init]) {
balls = [NSMutableArray array];
[balls retain];
width = _width;
height = _height;
friction = _friction;
timeDelta = _timeDelta;
return self;
}
My question is that if I take out the [balls retain] line my program crashes but if I leave it in it works great. Why do I have to retain it? I thought the NSMutableArray:array method automatically set the retain count to 1.
-(id) initWithWidthint)_width Heightint)_height Frictionfloat)_friction TimeDeltafloat)_timeDelta {
if(self = [super init]) {
balls = [NSMutableArray array];
[balls retain];
width = _width;
height = _height;
friction = _friction;
timeDelta = _timeDelta;
return self;
}
My question is that if I take out the [balls retain] line my program crashes but if I leave it in it works great. Why do I have to retain it? I thought the NSMutableArray:array method automatically set the retain count to 1.