Я пытаюсь выучить Objective-C. Я почти закончил одно упражнение, но оно не освобождает память:
Вот что у меня есть:
void PrintPolygonInfo() {
NSLog(@"--------------------");
NSLog(@" PRINT POLYGON INFO");
NSLog(@"--------------------");
NSMutableArray *array = [[NSMutableArray alloc] init];
PolygonShape *p1 = [[PolygonShape alloc] initWithNumberOfSides:4 minimumNumberOfSides:3 maximumNumberOfSides:7];
PolygonShape *p2 = [[PolygonShape alloc] initWithNumberOfSides:6 minimumNumberOfSides:5 maximumNumberOfSides:9];
PolygonShape *p3 = [[PolygonShape alloc] initWithNumberOfSides:12 minimumNumberOfSides:9 maximumNumberOfSides:12];
[array addObject:p1];
[array addObject:p2];
[array addObject:p3];
// Log the descriptions
for (id shape in array) {
NSLog(@"%@", shape);
}
// Test the constraints
for (PolygonShape *shape in array) {
[shape setNumberOfSides:10];
}
[p1 release];
[p2 release];
[p3 release];
}
Это сделка ():
- (void) dealloc {
NSLog(@"Deallocated!!!");
[super dealloc];
}
И вот результаты:
2009-11-19 06:58:17.030 Assignment 1B[5441:a0f] --------------------
2009-11-19 06:58:17.030 Assignment 1B[5441:a0f] PRINT POLYGON INFO
2009-11-19 06:58:17.031 Assignment 1B[5441:a0f] --------------------
2009-11-19 06:58:17.031 Assignment 1B[5441:a0f] init: Retain count of 1.
2009-11-19 06:58:17.032 Assignment 1B[5441:a0f] init: Retain count of 1.
2009-11-19 06:58:17.032 Assignment 1B[5441:a0f] init: Retain count of 1.
2009-11-19 06:58:17.033 Assignment 1B[5441:a0f] Hello I am a 4-sided polygon (aka a Square) with angles of 90 degrees (1.570796 radians).
2009-11-19 06:58:17.033 Assignment 1B[5441:a0f] Hello I am a 6-sided polygon (aka a Hexagon) with angles of 120 degrees (2.094395 radians).
2009-11-19 06:58:17.034 Assignment 1B[5441:a0f] Hello I am a 12-sided polygon (aka a Dodecagon) with angles of 150 degrees (2.617994 radians).
2009-11-19 06:58:17.034 Assignment 1B[5441:a0f] Invalid number of sides: 10 is greater than the maximum of 7 allowed
2009-11-19 06:58:17.035 Assignment 1B[5441:a0f] Invalid number of sides: 10 is greater than the maximum of 9 allowed
Как видите, сообщение «Deallocated !!!» не печатается:
Может кто-нибудь сказать мне, что я делаю не так, пожалуйста?
Заранее спасибо