本文介绍了iPhone-UIImage Leak,ObjectAlloc构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我很难跟踪此内存泄漏.运行此脚本时,我看不到任何内存泄漏,但是我的objectalloc正在攀升.仪器指向CGBitmapContextCreateImage> create_bitmap_data_provider> malloc,这占了我的objectalloc的60%.

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.

使用NSTimer多次调用此代码.

This code is called several times with a 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;
    }

推荐答案

您使用的此方法实例化UIImage并将其设置为自动释放.如果要清理这些,则需要定期清空池

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];

常见的做法是将它们放在for循环和其他方法中,这些方法使许多自动释放的对象成为可能.

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]

这篇关于iPhone-UIImage Leak,ObjectAlloc构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 14:33