iPhone - UIImage 泄漏、ObjectAlloc 构建

发布于 2024-08-05 09:31:07 字数 757 浏览 15 评论 0原文

好吧,我很难追踪这个内存泄漏。运行此脚本时,我没有看到任何内存泄漏,但我的 objectalloc 正在攀升。 Instruments 指向 CGBitmapContextCreateImage >创建位图数据提供者> malloc,这占用了我的 objectalloc 的 60%。

使用 NSTimer 多次调用此代码。

返回后如何清除 reUIImage?

...或者如何才能使 UIImage imageWithCGImage 不构建我的 ObjectAlloc?

    //I shorten the code because no one responded to another post
    //Think my ObjectAlloc is building up on that retUIImage that I am returning
    //**How do I clear that reUIImage after the return?**

-(UIImage) functionname {
    //blah blah blah code
    //blah blah more code

    UIImage *retUIImage = [UIImage imageWithCGImage:cgImage];
            CGImageRelease(cgImage);

            return retUIImage;
    }

Alright I am having a world of difficulty tracking down this memory leak. When running this script I do not see any memory leaking, but my objectalloc is climbing. Instruments points to CGBitmapContextCreateImage > create_bitmap_data_provider > malloc, this takes up 60% of my objectalloc.

This code is called several times with a NSTimer.

How do I clear that reUIImage after I return it?

...or How can I make it so that UIImage imageWithCGImage does not build my ObjectAlloc?

    //I shorten the code because no one responded to another post
    //Think my ObjectAlloc is building up on that retUIImage that I am returning
    //**How do I clear that reUIImage after the return?**

-(UIImage) functionname {
    //blah blah blah code
    //blah blah more code

    UIImage *retUIImage = [UIImage imageWithCGImage:cgImage];
            CGImageRelease(cgImage);

            return retUIImage;
    }

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

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

发布评论

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

评论(1

蛮可爱 2024-08-12 09:31:07

您使用的此方法实例化一个 UIImage 并将其设置为自动释放。如果你想清理它们,你需要定期清空池。

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
..
..
..
[pool release];

请注意,它们可以嵌套:

NSAutoreleasePool *pool1 = [[NSAutoreleasePool alloc] init];
NSAutoreleasePool *pool2 = [[NSAutoreleasePool alloc] init];
..
..
..
[pool2 release];
[pool1 release];

常见的做法是将它们放置在 for 循环和其他生成许多自动释放对象的方法周围。

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
for (Thing *t in things) {
  [thing doAMethodThatAutoreleasesABunchOfStuff];
}
[pool release]

this method you use instantiates a UIImage and sets it as autorelease. If you want to cleanup these, you will need to empty the pool periodically

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
..
..
..
[pool release];

Note that these can be nested:

NSAutoreleasePool *pool1 = [[NSAutoreleasePool alloc] init];
NSAutoreleasePool *pool2 = [[NSAutoreleasePool alloc] init];
..
..
..
[pool2 release];
[pool1 release];

Common practice is to place these around for loops and other methods that make many autoreleased objects.

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
for (Thing *t in things) {
  [thing doAMethodThatAutoreleasesABunchOfStuff];
}
[pool release]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文