0
votes

This is the body of the selector that is specified in 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];

Even with the autorelease pool present, I get this printed to the log when I call 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

Has anyone else seen this with UIGetScreenImage() on a separate thread?

1

1 Answers

0
votes

[pool drain] on iOS behaves the same as [pool release]. So after the first iteration of your while loop you end up with having no autorelease pool in place. Remove the drain and you should be fine. Not sure whether it's OK to use UIGetScreenImage() in threads other than the main thread, though.