简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM