#import #import "polygon.h" @implementation Polygon -(id) init { [super init]; points = [[NSMutableArray alloc] init]; return self; } -(void) addPoint:(Point*) p { // the array will retain p on its own, but for this example // I wanted it to be explicit that the Polygon retains the points [p retain]; [points addObject:p]; } -(Point*) getPoint:(int) i { return [points objectAtIndex:i]; } -(void) dealloc { // see note about retained points above printf("Polygon.dealloc\n"); // apologies for the Java notation here for (int i = 0; i < [points count]; i++) { [[points objectAtIndex:i] release]; } [points release]; [super dealloc]; } @end