Please note, this blog entry is from a previous course. You might want to check out the current one.
Keep as little of the photos’ image data in the heap as you can (i.e. don’t keep strong pointers to any NSData and/or UIImage objects that you are not currently displaying). You should have at most 2 photos’ image data in memory at a given time, preferably only 1 (or 0 if none are in the process of being viewed or fetched).
The current code up to this task does not keep any strong pointers to NSData or NSImage objects as the image is only stored in the image view. Because the iPad uses a single image view there is at most only one image in memory. The iPhone has two image views thus there could be two images in memory. (Using the profiler proves that behavior)
To avoid the two images in memory for the iPhone we can remove it as soon as the image view disappears from screen. Then the image loading needs to be moved from when the view is loaded to were it appears on screen (because of the tab views where the view is loaded only once):
- (void)viewDidLoad { ... //[self resetImage]; ... } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self resetImage]; } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; self.imageView.image = nil; }
The complete code is available on github.