5

I'm testing on an iPhone 4 running iOS 7.1 attached to Xcode 5.1.1. I don't understand why I am getting memory warnings and even crashes when instruments shows my app is only using a few megabytes and there is plenty of memory free (see attached). Any ideas?

Memory Utilization of App while Receiving Warnings

Update:

In instruments, as I suspected, I found no leaks, but the "Anonymous VM" size seems unduly large and filled with image data. Each table cell in my app displays a JPEG. Perhaps I should be pre-scaling these images and that is the cause of the large Anonymous VM size... More investigation to be done.

Instruments Allocations

davecom
  • 1,499
  • 10
  • 30
  • 1
    You could have a lot of leaks...have you checked for this in instruments? Run the static analyzer? – Reid Sep 02 '14 at 22:29
  • If I had a lot of leaks would that not be showing up as memory utilized growing over time (see attached screenshot)? – davecom Sep 02 '14 at 22:32
  • I don't believe so, no...I may be mistaken and if so, others will correct me. But the whole idea of a memory leak is that a pointer to some memory address has fallen out of scope and been destroyed, without that memory having been released, so intuitively I do not think that leaked memory would be shown by the tools as "owned" by your app...in any case, why not just check? It's something we ought to do routinely, anyway. – Reid Sep 02 '14 at 22:44
  • I updated the question to address this - found no leaks but interesting other bits. – davecom Sep 04 '14 at 06:53

2 Answers2

3

It turned out images displayed in UIImageViews in each and every table cell were being stored in memory at their full size, not the scaled size (size of the UIImageView). This only showed up in the "Anonymous VM" in Instruments (since iOS only stores references to your images in your application heap and the actual image caches are in system memory it seems), not in the basic memory usage displayed in Xcode. I resolved the issue by pre-scaling my images before putting them into the UIImageViews of the table view cells. There were no leaks.

davecom
  • 1,499
  • 10
  • 30
1

Instrument is sometimes imprecise about the real memory used. The best way to measure is to print the memory usage on the console.

I found the code on this thread: Programmatically retrieve memory usage on iPhone

Community
  • 1
  • 1
David Bemerguy
  • 1,334
  • 11
  • 15