这是NSThread +detachNewThreadSelector:(SEL)aSelector toTarget:(id)aTarget withObject:(id)anArgument
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; while (doIt) { if (doItForSure) { NSLog(@"checking"); doItForSure = NO; (void)gettimeofday(&start, NULL); /* do some stuff */ // the next line prints "_NSAutoreleaseNoPool():" message to the log CGImageRef screenImage = UIGetScreenImage(); /* do some other stuff */ (void)gettimeofday(&end, NULL); elapsed = ((double)(end.tv_sec) + (double)(end.tv_usec) / 1000000) - ((double)(start.tv_sec) + (double)(start.tv_usec) / 1000000); NSLog(@"Time elapsed: %e", elapsed); [pool drain]; } } [pool release];
即使存在自动释放池,我也会在打电话UIGetScreenImage()
时将其打印到日志中:
2010-05-03 11:39:04.588 ProjectName[763:5903] *** _NSAutoreleaseNoPool(): Object 0x15a2e0 of class NSCFNumber autoreleased with no pool in place - just leaking
是否有其他人在单独的帖子中看到UIGetScreenImage()
?
答案 0 :(得分:0)
[pool drain]
与[pool release]
的行为相同。因此,在while循环的第一次迭代之后,您最终没有自动释放池。删除drain
,你应该没事。但是不确定在主线程以外的线程中是否可以使用UIGetScreenImage()。