Reputation: 5088
When running The Allocations Instrument at any given moment my iPad app has less than 5MB of memory allocated. I've been very thorough and made sure everything is being released correctly. My app is a tab bar app that does load a lot of images, videos, and PDFs. I've made sure to handle this appropriately and empty caches, etc to free up memory.
However, when I run the Activity Monitor Instrument, with my app running on my iPad, the memory usage of my app gradually increases eventually reaching over 100MB and crashes.
I'm not really sure what to do and there isn't a specific block of code that is causing issues. The entire app is a memory hog and I've never had this issue before.
Besides allocations what reasons would my app consume this much memory? Is there another tool I can use to trace what processes are using up memory?
Edit: As someone mentioned, I've used Build and Analyze to make sure all issues have been cleaned up.
Upvotes: 0
Views: 630
Reputation: 7200
Lots of times CGImages and other large media blobs do not show up on Allocations - they might show up as some small innocent looking object, but they point to some large object like an image that is allocated using 'weird' techniques (like memory mapped files, video card memory, etc). The activity monitor instrument on the other hand looks at memory used in terms of 4k pages loaded for your app, and thus includes these media blobs.
I don't know what your caching scheme is. Here is a scenario: You need to load 50 100k jpegs - the user will see only a max of 3 at once. 50 100k images is 5MB of memory. So you can load all the data for the jpegs from the internet. If you then create 50 CGImages from this data then each one will consume (assuming the jpegs are 1000x1000 * 4bytes per pix = ) 4MB of memory. So that would be 200MB to sit them all in memory. Which won't work. So you need to keep the 100k compressed nsdata blobs around, then only create the 1 or 3 CGimages at a time that you need them. Its an art to keep things smooth and balanced.
In other workds: in Allocations - look at the number of CGImageRefs, etc that you have at any one time, and lower that number.
Upvotes: 2