ios - UIImageView data persists despite removing image -
I have an app that shows two full-screen images, one at a time, a UIImageView . When the user taps the first image, it fades out and displays the next one. After the second image is displayed, it is cleaned and no new image is displayed - and hopefully nothing remains in memory.
However, while analyzing the app in the device, I see that each image has memory of 12 MB, but it cumulates. When 12 MB shows the first image, 24 MB when the second image shows, and then 24 MB remains when the image is cleaned up. I am wrestling with this for some time, and can not see where this data is kept.
A new set of eyes will be great on this code. This is the method that every time the user taps the image:
- (zero) display images {[self.slideshow image set user interface enabled: yes]; Int imageNumber = (int) self.slideshowImage.tag; // If fade in first image (imageNumber == 0) {self.slideshowImage.alpha = 0; [Self.slideshowImage setImage: [UIImage imageNamed: [slideshow images object addinx: image number]]]; [UIView Animation: 0.3 Animation: ^ (Zero) {self.slideshowImage.alpha = 1; } Closing: ^ (BOOL Finish) {self.slideshowImage.tag = imageNumber + 1; }]; // erase the current image, fade in the next image; And if (Image number: [Count of slideshow images]) {UIImageView * newImage = [[UIImageView alloc] initWithFrame: self.slideshowImage.frame]; [New image set image: [UIImage imageNamed: [slideshow images object addinx: image number]]]; NewImage.alpha = 0; [Self.view addSubview: newImage]; [UIView Animation: 0.3 Animation: ^ (Zero) {self.slideshowImage.alpha = 0; } Closing: ^ (BOOL Finish) {[UIView animateWithDuration: 0.3 Animation: ^ (zero) {newImage.alpha = 1; } Closing: ^ (BOOL Finish) {[Self.slideshow Image Set Image: [UIImage imageNamed: [Slide Show Images AutoText: Image Number]]]; Self.slideshowImage.alpha = 1; [Remove new imageprosy preview]; }]; }]; Self.slideshowImage.tag = Image NUMBER + 1; // clear image} other {[UIView animated dislocation: 0.3 Animation: ^ (zero) {self.slideshowImage.alpha = 0; } Closing: ^ (BOOL Finish) {[self.slideshow Image Settag: 0]; [Swastover: Image Set Image: Zero]; [Automatically slideshow image set user interaction enabled: No]; }]; }} Thanks for reading!
This implementation is the cache of all the images in it.
The document describes a paragraph that is happening in your code:
If you have an image file that will only be displayed once and It wants to make sure that it does not connect to the system's cache, you should use your image instead, it will keep your single-use image out of the system image cache, potentially using your app's memory Attribution of attributes In.
But if you want to perform well then it is almost always better to use the system cache to load an image of a 12MB image can take more than 16 meters and UI will be delayed.
Comments
Post a Comment