I want to know how does iOS utilizes memory when displaying images…
for instance:
I have an image that its 2000w, 2000h, but the iphone, ipod in this particular case has a rectangle of 460×920 (just an example)… if the image is just visible for the rectangle of the iOS device, i know for sure that memory is being used, but what happens to the rest of the image that is NOT CURRENTLY drawn in the rectangle? is that memory being consumed? or iOS is smart enough that is not using memory only for the drawn section? or is this considered as memory-leak?
I am wondering this because in some games you need longer scenarios with big images in which using parallaxnodes or anything similar helps. But I started to wonder how this affects my memory.
Thanks in advance for your answers.
On iPhone 4 you have 512MB of RAM. It’s shared between CPU and GPU, which means Video RAM consumes a part of it.
If you are talking about a
UIImageallocated 2000 by 2000 pixels. Even if it’s off-screen, it DOES consume RAM. To be precise, it consumes 2000*2000*4, around 16MB. This is managed by Objective-c runtime. This is a fairly large amount. As far as I know, the maximum size of aUIImageon the 4 series devices is 2048×2048, and 1024×1024 on 3 series.The viewing rectangle, or the screen you are talking about, is a part of the Video RAM. Typical displaying procedure involves compositing the image in Video RAM so that the graphics hardware can display it.
Therefore, you have two copies of the image inside this 512MB of RAM. One you can load and modify by code (RAM), the other, smaller one for displaying (VRAM). Though in VRAM, only the size of the screen is used.
And no, this isn’t memory leak.