I am having a problem with memory I cant get straightened out. What I am doing is this:
I have a viewcontroller that looks similar to a book with 7 different tabs. Each time the user presses a tab, the content on the “page” changes and the background image changes to reflect the different tab selected. Each background image is 768×1024 and there is one for each of the 7 tabs.
My problem is that when each tab is selected, the memory is never released for the previous image, and after 7 tabs are selected I have something like 30MB being used up for 7 different images. I have 7 different methods for each of the 7 tabs that the user presses.
-(IBAction) pressedTab1 {
self.tabsImageView.image = nil; //tabsImageView is the imageView I am keeping he background image in.
UIImage *tempUIImage = [UIImage imageNamed:@"tab1selected.png"];
self.tabsImageView.image = tempUIImage;
}
There is no leak in the code that you have posted. When you tapped all 7 tabs then your app reaches 30MB of memory. But what happens if you continue to switch among tabs? Does it continue to increase in every switch? If yes, then you definitely have leak in some other portion. If not (i.e memory is more or less 30MB constant), then this might not be a problem at all. Sometimes system don’t free up things until memory is required and 30MB is acceptable. It may also cache image data. You don’t need to be worried in this case. Though I have found no Apple doc stating this feature, I have faced a similar scenario.
Apart from your original question, one thing is you should really avoid such big images (768×1024 pixel). This may cause huge problem, at least in low end devices.