本文介绍了我如何解决内存泄漏问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个简单的应用程序,在其中设计或创建代码,其中我创建了UIImage的实例对象。当我在Ipad屏幕上翻转时,它构成了一个sreen的图像和我渲染到UIImage对象的图像,之后我将这个图像设置为UIImageView对象和UIimage对象。
每次我在屏幕上滑动,上面的过程就是一次又一次。但它让我泄漏了 renderImage = [[UIImage alloc] init];

I developing an simple application in which design or make code in which i creating and instance object of UIImage. When i swip on Ipad screen it make up an image of the sreen and that image i render into UIImage object after that this image i set into UIImageView object and UIimage object is released.Every time i swipe on the screen and above process is does again and again. But it give me leak in renderImage = [[UIImage alloc] init];.

Code,

_renderImage = [[UIImage alloc] init];

_textImageV = [[UIImageView alloc] init];

[self renderIntoImage];

-(void)renderIntoImage
{

    UIGraphicsBeginImageContext(bgTableView.bounds.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    _renderImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
}

 _textImageV.image = _renderImage;
[_renderImage release];

完成滑动过程后我也发布了_textImageV。

after completing the process of swipe i also releasing _textImageV.

我如何解决UIImage * _renderImage中的内存泄漏问题?

How i solve the memory leak problem in UIImage *_renderImage?

推荐答案

在这一行:

_renderImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsGetImageFromCurrentImageContext()返回一个新的自动释放 UIImage 并将 _renderImage ivar指向它。以前分配的 UIImage 从未实际发布过,它的变量只是被重新命名到其他地方。

UIGraphicsGetImageFromCurrentImageContext() returns a new autoreleased UIImage and points the _renderImage ivar to it. The previously allocated UIImage is never actually released, the variable to it is just repointed to somewhere else.

这个放弃了 UIImage 导致/是内存泄漏。您应该在将 _renderImage 指向其他内容之前将其释放,或者您可能不会在第一时间分配它。

This abandoned UIImage causes/is the memory leak. You should either release it before pointing _renderImage to something else, or you could just not allocate it in the first place.

这篇关于我如何解决内存泄漏问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 06:09