tags:

views:

165

answers:

2

I have this function:

-(void) debugPrint
{
    printf("name: %s", [_name UTF8String]);
}

This results in a runtime error:

[Session started at 2009-03-21 15:02:26 -0700.] 2009-03-21 15:02:26.319 TGui[20063:10b] *** _NSAutoreleaseNoPool(): Object 0x10a290 of class NSCFData autoreleased with no pool in place - just leaking Stack: (0x9234c73f 0x92258e32 0x9226d505 0x9226d0e1 0x2406 0x22ce 0x20be) name: name

What's weird is that when I do [_name cString], it works fine.

A: 

Whoops--I was putting the all to debugPrint in main(), before the call to "return NSApplicationMain(argc, (const char **) argv);". This was causing problems.

Sam Lee
+1  A: 

The thread on which you call that method doesn't have an NSAutoreleasePool, so autoreleased objects have no pool. You have to set up an NSAutoreleasePool for each thread. The intro for the NSAutoreleasePool documentation explains this idea in greater detail.

mipadi