Reputation: 527
I have a UIImageView that was created programmatically ([[UIImageView alloc] init]
). The app's memory stays in check until the setImage:
method is called. Any thoughts?
Upvotes: 1
Views: 138
Reputation: 8576
I'm assuming you're setting your image to your image view using something like this:
[imgV setImage:[UIImage imageNamed:@"yourImg.png"]]
The problem with using that is that the app caches these images. If you'd like to avoid caching images, use imageWithContentsOfFile:
:
[imgV setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"yourImg.png" ofType:nil]]];
Also, be sure to set your image to nil
when you're done using it:
[imgV setImage:nil];
I have had issues with this in the past, and here's some text from an email I got back from Apple in response to a TSI:
There are quite a few cases where you’re using the API UIImage +imageNamed: to load images but you should be aware that imageNamed caches its image data even after the returned UIImage object is released. Replacing calls to imageNamed with -imageWithContentsOfFile: as outlined below is a way to ensure full control over your app’s image data in memory
Upvotes: 3