I'm new to using Instruments and to test the Instruments Leaks template I came up with the following simple test:
1. I created a new Cocoa application using the Cocoa Document-Based Application template.
2. Then I created an empty class named Duck, inheriting from NSObject.
3. Then I placed the following code into main.m, inside the main method, above its return statement:
printf("In main.m: Intentional leak - A Duck is created and not released.\n");
Duck *duckA;
duckA = [[Duck alloc] init];
printf("In main.m: Duck retainCount:%d\n\n", [duckA retainCount]);
4. Finally, in MyDocument.m, I overrode the windowControllerDidLoadNib: method as follows, creating three additional Duck object:
- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
[super windowControllerDidLoadNib:aController];
printf("In MyDocument.m: Intentional leak - A Duck is created and not released.\n");
Duck *duck;
duck = [[Duck alloc] init];
printf("In MyDocument.m: Duck retainCount:%d\n\n", [duck retainCount]);
printf("In MyDocument.m: Intentional leak - A Duck is created and not released.\n");
Duck *duck1;
duck1 = [[Duck alloc] init];
printf("In MyDocument.m: Duck retainCount:%d\n\n", [duck1 retainCount]);
printf("In MyDocument.m: Intentional leak - A Duck is created and not released.\n");
Duck *duck2;
duck2 = [[Duck alloc] init];
printf("In MyDocument.m: Duck retainCount:%d\n\n", [duck2 retainCount]);
}
Now here's my question: How come the Instruments leaks template identifies all three leaks from inside the windowControllerDidLoadNib: method, but not the one from inside main.m? Am I not configuring this template correctly? Or am I offbase even asking this, as adding code to main.m would not be normally required anyway?
thanks for anyone's help
glennB