Reputation: 7333
I have two large size images in the my view controller. The size of images are approximately 1500 x 1800. When I load that view controller a few times I am getting a memory warning and finally my app crashes. I did observe some memory uses. When I load the view controller my memory use is increased by 15 Mbs each time. I have read about image caching, so to avoid image caching I am not loading image from controller, instead I am loading image in the following way :
UIImage * image = [[UIImage alloc] initWithContentsOfFile:pathForImageFile1];
imageView.image = image;
image = nil;
I have declared image view inside .h file like :
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
By the documentation, If I use load image with initWithContentsOfFile method then image should not be cached and memory should be released once unloading of view happens.
Further I tried to nil image :
-(void)viewDidDisappear:(BOOL)animated
{
imageView = nil;
}
But there is no difference in memory usage. How can I release the memory used by imageview?
Upvotes: 0
Views: 509
Reputation: 696
Setting imageView
IBOutlet
to nil
will not unload your imageView
because strong
reference still remains in imageView
's superview
(subviews
array).
Unload image using:
-(void) viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
imageView.image = nil;
}
Upvotes: 2