use*_*949 1 iphone multithreading cocoa-touch objective-c
我正在创建一个这样的新线程:
[NSThread detachNewThreadSelector: @selector(myMethod:)
toTarget:self withObject:filePath];
Run Code Online (Sandbox Code Playgroud)
在我做的方法中:
- (void) myMethod:(NSString*)path{
NSAutoreleasePool *pool = [NSAutoreleasePool alloc];
[UIImagePNGRepresentation(theImage) writeToFile:[path stringByAppendingString:@".png"] atomically:NO];
[pool release];
}
Run Code Online (Sandbox Code Playgroud)
但不断得到这些警告:
*** _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)
Run Code Online (Sandbox Code Playgroud)
是不是在被调用的方法中创建了一个NSAutoreleaseNoPool对象,然后以正确的方式释放它以使用线程化的@selector?
您没有完全初始化自动释放池:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Run Code Online (Sandbox Code Playgroud)