How can I reliably free memory by removing UIImageViews from the screen?

I have UIImageViews that are nested in UIViews that group them together. They belong to the view controller. As soon as the -viewWillDisappear method is called, I want to remove these UIImageViews from their UIViews alltogether so that the memory is freed.

I call -release on UIViews that contain UIImageViews as subviews. Nothing else belongs to UIImageViews. All I have is an instance variable in a UIView that groups a UIImageView together.

So, when I send-excite, the save account should become 0. But this is not a guarantee that I get more free memory, right? So, I also set myUIView = nil. Is this helpful / helpful? How do you free memory safely?

+3
source share
1 answer

The best thing you can do in -viewDidDisappear(not -viewWillDisappear; you are still on the screen at this point) is to call for this self.view = nil. This resets the entire view of the controller controller, which will automatically restart for you the next time you need it.

If you have any IBOutlets in these views, you need to set them to zero, otherwise they will not be released. Assuming you have this setup:

@interface MyViewController : UIViewController
{
   UIImageView *_imageView;
}
@property (readwrite, retain) IBOutlet UIImageView *imageView;

@implementation MyViewController
@synthesize imageView = _imageView;

Then you need to call self.imageView = nilin your `-viewWillDisappear.

-release ivars, -dealloc. , .

-release, saveCount 1, free(), . , , , , , .

, , . ; , , . , -dealloc , :

[_stuff release]; _stuff = nil;
[_otherStuff release]; _otherStuff = nil;
+3

Source: https://habr.com/ru/post/1708983/


All Articles