small medium large xlarge

16 Mar 2009, 20:16
Jamaal Speights (2 posts)

Here was my solution for section 7.10. It still works without any leaks.

in main.m I added the function above main()

void greetAPerson(NSString *name){ Greeter *personGreeter = [[Greeter alloc] initWithName:name]; [personGreeter sayHello]; [personGreeter release];


in main() I called this function like so

int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];


[pool release];
return NSApplicationMain(argc,  (const char **) argv); }

Here is my implentation of initWithName:theName in Greeter.m

-(id) initWithName:(NSString *)theName{

self = [super init];
if (self != nil) {
	greetee = theName; 
return self; }

I have no memory leaks what so ever. Also when I try to print the retain count of “theName” or “name” I get a strange number like.

[Session started at 2009-03-16 15:58:52 -0400.] 2009-03-16 15:58:52.748 HelloWorld[17702:10b] retain count for name 2147483647 2009-03-16 15:58:52.751 HelloWorld[17702:10b] Hello, TIMMAAA!.

[Session started at 2009-03-16 16:00:07 -0400.] 2009-03-16 16:00:07.116 HelloWorld[17751:10b] retain count for name 2147483647 2009-03-16 16:00:07.118 HelloWorld[17751:10b] Hello, TIMMAAA!.

I am curious why the book says to use greetee = [name retain] in the initWithName method when it doesnt even seem like “name” or in my case “theName” doesn’t even have a correct name count or any memory leaks.

30 Jun 2009, 19:54
Sondre Selnes (3 posts)

Did you remember - @syntesize greetee; ?

You must be logged in to comment