Search code examples
iphoneobjective-cmemoryinstrumentsmemory-warning

Memory warning and crashing app - can't find source of issue


My app is constantly crashing after receiving many memory warnings. It is almost thirty thousand lines of code long so it is not easy to track the problem. I have run it through instruments and there are up to 30MB of live bytes at some stages, which should not be too much of an issue as far as I am aware. The memory leaks are extremely minimal, so they can not be the problem. The app tends to crash after playing it for long periods of time. Nothing in instruments has helped me to track the source of the memory warnings I am constantly receiving. Is there any other possible way to do this? It is very important that this doesn't happen for obvious reasons. Any help is greatly appreciated.


Solution

  • Actually, 30MB of live bytes are not that little memory, in my experience. IMO, it is ok to consume up to large amounts of memory but only for a very short time, then go back to safer levels of memory occupation (which if you want to address iPad1 should be between 10 and 15/20 MB).

    I think this is the case for "abandoned memory", i.e., memory which is allocated and, although it could be freed, is never (or too late).

    Have a look at this post to learn about snapshot memory analysis, which could help in your case.

    Of course there is also a chance that your app does need that much memory (e.g., because of some large resources it handles), and in this case the path forward would be trying to reduce required memory (and this highly depends on the kind of data your app manages. If it is a game, e.g., you could use an RGB565 format instead of RGBA8888 for your artworks).

    Besides, if Instruments allows you to pin down a certain number of cases where the memory consumption goes up, you could work on those to remove all leaks you have, or remove abandoned memory, or optimize your app memory consumption requirements.