开发者

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

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.

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


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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜