My iphone app is having memory problems and eventually crashes - uses a lot of images
I am new to programming (learned how to write apps a few months ago) and recently wrote an app that crashes every time after about 5 minutes with several 'Received memory warning. Level=1' warnings. While testing with instruments, I have been unable to detect any leaks and I'm fairly confident I'm releasing the objects correctly so I suspect the memory problems stem from the large number of png images I use (around 80). I've tried changing from the -imageNamed method to -imageWithContentsOfFile and saw no real improvement. If anyone could offer any tips I 开发者_JS百科would really appreciate it since I am completely stuck.
Running out of memory does not necessarily imply memory leaks. It could mean that you've asked for too much memory at once. In your case, you're probably trying to create too many UIImage
objects that all exist simultaneously. Without seeing a lot more of your code, there's not much to say except try and find a way to use fewer images at the same time.
Supposedly UIImage
s which you load using imageNamed
offload their contents when possible, if they receive memory warnings. UIImage Reference, see Images and Memory Management That would leave only a very small, empty UIImage
container. So I suspect that you have some other problem.
Check for any loop within your program and make sure it doesn't leak in some way.
also remember that PNGs on disk are much smaller than the corresponding image in memory. if your PNGs are large, you could just be using up too much memory. maybe you can delay-load images to make your footprint smaller.
精彩评论