代码之家  ›  专栏  ›  技术社区  ›  jtrim

在手动生成的线程上调用UIGetScreenImage()将打印“NSAutoreleaseNoPool():”消息以记录

  •  0
  • jtrim  · 技术社区  · 16 年前

    这是在中指定的选择器的主体 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() 在另一条线上?

    1 回复  |  直到 16 年前
        1
  •  0
  •   Ortwin Gentz    15 年前

    [pool drain] 在iOS上的行为与 [pool release] . 因此,在while循环的第一次迭代之后,您最终没有自动释放池。移除 drain 你应该没事的。但不确定在主线程以外的线程中使用UIGetScreenImage()是否可以。