I created an application, and he (well, he was) ready to ship.
The application is an application for flash cards for children, where there are 12 cards per page.
Currently, only an iPad and when the cards touch the image animated from the card in full screen with a full resolution of 2048 x 1536 and it reproduces the sound of the animal, you click on the full-sized image and it goes back to the card. Each card has 5 images assigned to it. The application works fine, although the design period is now that I downloaded all the animals, and I tested it and noticed that it crashed.
In short, memory is constantly growing at 12 MB per image (although each image is about 200-400 KB) until it reaches 700 MB of memory, and it will work. This memory never decreases.
I started the application through xcode tools and I donβt see any leaks, but I identified in "Allocations" that this is the category "ImageIO-jpeg-data", which is the culprit.
I read about it all evening, as I found some encouraging results, but these results did not work for me, so I assume that I misunderstood what was recommended, or I did not understand, so I hoped that someone could help to me or explain in the conditions of the laity how I can resolve this.
OK to explain how to set up a Contoller view.
Initially, I set up 5 images for each map in the array, but there was a delay, so someone here recommended to preload the images in viewDidLoad, and then call them when you touch the map / button.
So for example, I used this format in viewDidLoad
domestic100 = [UIImage imageNamed:@"ferret-00"]; domestic101 = [UIImage imageNamed:@"ferret-01"]; domestic102 = [UIImage imageNamed:@"ferret-02"]; domestic103 = [UIImage imageNamed:@"ferret-03"]; domestic104 = [UIImage imageNamed:@"ferret-04"];
and then with the mouse button clicked I assigned the image to the image by calling:
domestic01ImageContainer.image = domestic100;
inside if if else check if the number of images was from 1 to 4.
In any case, it worked perfectly (apart from this problem)
I read online that I would be better off declaring uiimages using
[UIImage imageWithContentsOfFile:path]
as can be seen from this article: UIImage memory does not free VM: ImageIO_JPEG_DATA?
So, the changes I made in my code are:
in my view of DidLoad Now I create uiimages:
domestic200 = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"dog-00" ofType: @"jpg"]]; domestic201 = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"dog-01" ofType: @"jpg"]]; domestic202 = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"dog-02" ofType: @"jpg"]]; domestic203 = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"dog-03" ofType: @"jpg"]]; domestic204 = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"dog-04" ofType: @"jpg"]];
and then with the pressed button, call the image into the image using
[domestic01ImageContainer setImage:domestic100]
I get the same results - the image is simply expanded in one memory, and not freed or freed.
I donβt wiz when it comes to objective-c, and this is my first real application.
If someone could be kind enough to spare a moment of his time to help me, I would be very grateful.
Thanks in advance.
****** Change ******
So, I told you how I upload my images above, I also provide 12 images in viewDidLoad, a starting point and hidden alpha.
domestic01ImageContainer = [[UIImageView alloc] initWithFrame:CGRectMake(30, 123, 152, 224)]; domestic01ImageContainer.Alpha = 0;
Then I add subview with:
[self.view addSubview:domestic01ImageContainer]
a highlight gesture is allocated to each image to hide the image at a later point:
UITapGestureRecognizer *domestic01Tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTaped:)]; [domestic01ImageContainer addGestureRecognizer:domestic01Tap]; [domestic01ImageContainer setUserInteractionEnabled:YES];
When you click on the thumb / card, the optimized version of the button will be:
- (IBAction)domestic01ButtonClicked:(id)sender { static int imageNumber = 0; if (imageNumber == 0) { [domestic01ImageContainer setImage:domestic100]; imageNumber++; } else if (imageNumber == 1) { [domestic01ImageContainer setImage:domestic101]; imageNumber++; } else if (imageNumber == 2) { [domestic01ImageContainer setImage:domestic102]; imageNumber++; } else if (imageNumber == 3) { [domestic01ImageContainer setImage:domestic103]; imageNumber++; } else if (imageNumber == 4) { [domestic01ImageContainer setImage:domestic104]; imageNumber = 0; } domestic01ImageContainer.Alpha = 1; [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{ domestic01ImageContainer.frame = CGRectMake(0, 0, 768, 1024); } completion:^(BOOL finished) { }];
}
In my imageTapped resolver, to compress the full image to the map I use:
[UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{ domestic01ImageContainer.frame = CGRectMake(30, 123, 152, 224); } completion:^(BOOL finished) { domestic01ImageContainer.Alpha = 0; }];
Basically, insert the flash card from full screen mode into the size of the card / thumbnail and set alpha to 0 again.
As I said, everything works, but since you assumed that the image is saved somewhere.
Hope this sheds a little more light on what might cause the problem.
I tried to set the image to zero after the sample was set to 0, but this did not clear the memory.
[domestic05ImageContainer setImage:nil]