views:

245

answers:

1

Hi,
i have a UIImageView of 1024x768 (the room of my game) and other various UIIMageView on it (the object of my game).
The iPhone screen is smaller than the room (UIImageView 1024x768) .. i want to understand if the iPhone's system automatically intercepts the graphic elements outside the visible area of Room (the player's view) and unload temporarily (for memory optimization) or i must do this by hand??

thanks

+1  A: 

The memory for the UIImageView is always in memory as long as you retain it. As far as I know, the iPhone does not automatically unload the memory used by a UIImageView if it's outside the bounds of the screen. You will need to manage it yourself by making sure to call removeFromSuperview on the UIImageView if it's not on screen, and adding it when it will be on screen.

If you have a lot of images that you want to layer and move around, you might want to look into CALayer.

lucius
Adding onto this, a good time to unload off-screen images is in didReceiveMemoryWarning. You may as well keep everything cached until that gets called.
alltom
if I manually call removeFromSuperview if UIImageView it's outside the bounds of the screen have a real gain (continuosly add/remove from superview on the player's View movement are CPU expensive) ??and best removeFromSuperview or hidden=true??the last question.. maintain in room all the UIImageView (one for one sprite) is CPU or GPU expensive??
BQuadra
I haven't done any instrumented testing so I don't know. I would run the software as it is and run Instruments with the CPU Sampler to make sure that memory usage and CPU time isn't a problem, and if it is, find out where to fix it. My advice is not to optimize prematurely, and do so based on real data and not on rules of thumb, unless you have lots of experience with it already.
lucius