2010-01-01 104 views
1

我創建一個新的線程這樣的:多線程和「公正泄漏」警告

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

,並在方法我做的:

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

但不斷收到這些警告:

*** _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) 

是不是在被調用的方法內創建一個NSAutoreleaseNoPool對象,然後釋放它以正確的方式使用線程@selector?

回答

6

你沒有完全初始化自動釋放池:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
0

試試這個代碼:

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

// do stuff 

[pool drain]; 

希望這有助於