views:

116

answers:

1

I'm creating a new thread like this:

[NSThread detachNewThreadSelector: @selector(myMethod:) 
toTarget:self withObject:filePath];

and in the method I do:

- (void) myMethod:(NSString*)path{
NSAutoreleasePool *pool = [NSAutoreleasePool alloc];
[UIImagePNGRepresentation(theImage) writeToFile:[path stringByAppendingString:@".png"] atomically:NO];
[pool release];
}

but keep getting these warnings:

*** _NSAutoreleaseNoPool(): Object 0x194b1c0 of class NSConcreteMutableData autoreleased with no pool in place - just leaking
Stack: (0x305a2e6f 0x30504682 0x309084ff 0x3a0d 0x3050a79d 0x3050a338 0x9100cfbd 0x9100ce42)

*** _NSAutoreleaseNoPool(): Object 0x19014c0 of class NSCFString autoreleased with no pool in place - just leaking
Stack: (0x305a2e6f 0x30504682 0x3a30 0x3050a79d 0x3050a338 0x9100cfbd 0x9100ce42)

Isn't creating an NSAutoreleaseNoPool object inside the called method and then releasing it the proper way to use a threaded @selector?

+5  A: 

You didn't fully initialize the autorelease pool:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Zach Wily