在手动生成的线程上调用 UIGetScreenImage() 会打印“_NSAutoreleaseNoPool():”要记录的消息

发布于 2024-08-31 07:11:38 字数 1238 浏览 9 评论 0原文

这是在 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() 看到过这个吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧伤慢歌 2024-09-07 07:11:38

iOS 上的[pool排出][poolrelease]行为相同。因此,在 while 循环的第一次迭代之后,您最终会发现没有自动释放池。拆下排水管就可以了。但不确定是否可以在主线程以外的线程中使用 UIGetScreenImage() 。

[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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文