Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my app getting didReceiveMemoryWarning and gets killed although memory is constant and there is enough memory available?

I'm having strange effects with my app. I implemented my own PDF viewer. It shows ONE page at a time. Using Instruments Activity Monitor I see that my real memory is constantly at around 50MB. After switching pages forth and back a couple of times I receive a memory warning level 0. I do my best to react on it and sacrifice the low-res background image I'm rendering first to show something until CATiledLayer catches up. Does not help. A few pages later I get memory warning level 1 and level 2 and after a few more pages my app gets killed with reason "9". Memory NEVER goes above 50MB!

Why do I get those warnings in the first place? There IS enough memory available.

This is happening on on iPad running iOS 4.3.

like image 830
Krumelur Avatar asked Nov 05 '22 01:11

Krumelur


1 Answers

I don't think there's anything mysterious going on here -- which I'm sure is not what you wanted to hear. There are no absolute figures of "safe" amounts of memory to use. The rule is: when the OS tells you you're using too much, use less. It will jettison background processes first and in preference to your foreground app but there are still limits.

In the "olden days," you used to be lucky to get 20Mb. I'm sure you can safely get more than that on an iPad but, apparently, it's less than 50Mb.

You don't say how much memory you free by releasing the background image, but it seems that you need to be caching less data. You might also want to check Leaks (also in Instruments) to make sure you're releasing the objects you think you are.

like image 186
Stephen Darlington Avatar answered Nov 12 '22 21:11

Stephen Darlington