instruments with iOS: Why does Memory Monitor disagree with Allocations?

Brian picture Brian · Apr 1, 2011 · Viewed 8.5k times · Source

As can been seen in this screen shot from instruments, Allocations thinks my application (Ongo) is only using 7.55 MBs of memory, while Memory Monitor says 53.30. Further more the free system memory has little to no correlation to the amount of memory that the app is using. Does anyone know why there is such a big disagreement between these two tools? Additionally is it possible to find the source of the low system memory or how to keep it from running out so quickly? My app doesn't appear to be leaking memory but somehow it's exhausting the system resources.

Thanks

Instruments Y U Lie?

Answer

Brad Larson picture Brad Larson · Apr 11, 2011

I believe this is due to the fact that memory usage from OpenGL ES is hidden from ObjectAlloc, but counted in Memory Monitor. For example, see zoul's tests in his question here, where he observes a slight uptick in ObjectAlloc on creation of a texture, but then that memory disappears from that instrument when passed off to OpenGL ES. Memory Monitor still tracks that texture memory.

This should include the visual aspect of UI elements, like layers and views, because CALayers are effectively wrappers for OpenGL ES textures. The actual 2D image representation of your UI elements don't appear to be tracked by ObjectAlloc, which leads to the lower total values in ObjectAlloc.

ObjectAlloc is still good for tracking numbers and types of allocations, and is even more valuable since the advent of the heapshot functionality. You just want to partner it with Memory Monitor to look at your true overall memory usage.