In my application I use lots of images based in interface builder. The problem with this is that it uses large amounts of memory because interface builder caches it much liked "imageNamed" so I've begun removing the image from imageViews in interface builder and instead adding them once the view starts using "imageWithContentsOfFile". After several hours I have made little progress because I have literally hundreds of images. I'm just wondering if there is a more straightforward way to do this?
A:
Yes, don't do it. UIImage
and the whole xib business pretty much delay loading until things are needed, as well as drop cached images where possible and needed. You can even see this happening in Instruments. It helps to split your design over several xibs, so they can be loaded when needed.
What you can do however, is to make sure that you don't scale images but display them 1:1, and that you save them in the lowest acceptable quality. For photo's, take JPEG. For other images, take PNG.
mvds
2010-07-31 20:27:30
Oddly it doesn't really seem to be doing it, at least not well. In my dealloc method I'm deallocating all objects defined in the header but the amount of memory remains more or less the same because of the amount of images it dealt with. This only happens on iOS 4, if I run it on iOS 3 then it's fine.
Jeff
2010-07-31 20:53:34
But does it crash on low memory conditions?
mvds
2010-07-31 21:01:13
Yep, i've been monitoring its memory usage in instruments too.
Jeff
2010-08-01 08:28:37
You mean: "Yes, it crashes on low memory conditions"? Could you give an indication of what sizes your images have (in w*h as well as in kb)
mvds
2010-08-01 10:45:31
Are you sure there's no other source of memory leaks? Are you NSLog()ing things like `viewDidLoad` and `didReceiveMemoryWarning` to see what's actually happening?
mvds
2010-08-01 10:47:03