How do I solve a memory leak problem?

I am developing a simple application in which a design or code in which I create and an instance of a UIImage object. When I switch to the iPad screen, it forms an image of the screen and the image that I visualize in the UIImage object, after that this image, which I set in the UIImageView object, and the UIimage object are freed. Every time I sit down on the screen and above, the process runs over and over again. But this gives me a leak in renderImage = [[UIImage alloc] init]; .

the 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 swipe process, I also release _textImageV.

How to solve memory leak problem in UIImage * _renderImage?

0
memory-management memory-leaks iphone ipad
source share
1 answer

In this line:

 _renderImage = UIGraphicsGetImageFromCurrentImageContext(); 

UIGraphicsGetImageFromCurrentImageContext() returns the new autoreleased UIImage and points to _renderImage ivar. The previously allocated UIImage never released; the variable to it was simply redirected to another location.

This abandoned UIImage causes / is a memory leak. You must either release it before pointing _renderImage to something else, or simply cannot select it in the first place.

+4
source share

All Articles