Hello,
I would like to know what is the correct way of releasing Objects that are referenced in a NSMutableArray. Here is my simple code but I get warnings about memory leaks
I implemented the dealloc of my PolygonShape objects (to add a simple log) and they are not called by the 2nd loop. It looks like they are called only by [array dealloc]
Strange is that if I comment the dealloc loop, the [PolygonShape dealloc] method is not called at all.
What am I doing wrong here ?
Thanks,
Tex
I would like to know what is the correct way of releasing Objects that are referenced in a NSMutableArray. Here is my simple code but I get warnings about memory leaks
Code:
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSMutableArray *array = [[NSMutableArray alloc ] initWithCapacity:3];
[array addObject:[[PolygonShape alloc] init]];
[array addObject:[[PolygonShape alloc] initWithNumberOfSides:3]];
for(PolygonShape *curr in array) {
NSLog([curr description]);
}
for(PolygonShape *curr in array) {
[curr release];
}
[array release];
[pool drain];
return 0;
}
I implemented the dealloc of my PolygonShape objects (to add a simple log) and they are not called by the 2nd loop. It looks like they are called only by [array dealloc]
Strange is that if I comment the dealloc loop, the [PolygonShape dealloc] method is not called at all.
What am I doing wrong here ?
Thanks,
Tex