我如何解決內存泄漏問題?

[英]How i solve memory leak problem?


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

我開發了一個簡單的應用程序,在其中設計或創建代碼,其中我創建和UIImage的實例對象。當我在Ipad屏幕上翻轉時,它構成了一個sreen的圖像和我渲染到UIImage對象的圖像,之后我將這個圖像設置為UIImageView對象和UIimage對象。每次我在屏幕上滑動,上面的過程就是一次又一次。但是它讓我在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];

after completing the process of swipe i also releasing _textImageV.

在完成滑動過程后我也發布了_textImageV。

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

我如何解決UIImage * _renderImage中的內存泄漏問題?

1 个解决方案

#1


4  

On this line:

在這一行:

_renderImage = UIGraphicsGetImageFromCurrentImageContext();

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.

UIGraphicsGetImageFromCurrentImageContext()返回一個新的自動釋放的UIImage並將_renderImage ivar指向它。之前分配的UIImage實際上從未被釋放,它的變量只是被重新命名為其他地方。

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.

這個被遺棄的UIImage導致/是內存泄漏。您應該在將_renderImage指向其他內容之前釋放它,或者您可能不會首先分配它。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2010/12/21/8ecaacad921e59fcfc3cfd93ff69b5bd.html



 
  © 2014-2022 ITdaan.com 联系我们: