Domanda

Still pain with memory debugging. I have 4 VC's I load by using navigation controller. Every VC has its own PNG images used for several controls. In Instruments I realized that most of the VM regions are occupied by ImageIO_PNG_Data. And as I push/pop VC's those VM increases and never decrease (I was supposing that dealloc some VC would also release images). enter image description here

Of course, the debug is done in the Simulator.

È stato utile?

Soluzione

To expand slightly on rokjarc's comment:

UIImage +imageNamed: explicitly caches. The documentation states:

This method looks in the system caches for an image object with the specified name and returns that object if it exists. If a matching image object is not already in the cache, this method loads the image data from the specified file, caches it, and then returns the resulting object.

So images loaded previously will remain in the cache unless or until the memory is needed elsewhere. There's no efficiency to be gained from freeing memory up needlessly.

If you want to avoid the caching for whatever reason — I would argue whatever spurious reason — you could use +imageWithContentsOfFile:, or the normal init equivalent, having obtained the full path from NSBundle.

PNGs set to image views and other places via the interface builder will be accessed via the cache as far as I'm aware.

Altri suggerimenti

If the VM allocations do not have physical memory allocated to them there is no problem.

iOS memory maps files and there may be no physical memory allocated at any given time. Some VM allocations are frameworks that are shared by other apps.

What you need to watch are Living Heap Allocations which in this case is a little over 4MB.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top