Search code examples
xcodememory-managementcocos2d-iphoneuiimageccsprite

What are the pros and cons between UIImageView and CCSprite?


What are the pros and cons between UIImageView and CCSprite?

I am using UIImageView for our app's UI using initWithContentsOfFile: and I am afraid that it will cause too much memory than a CCSprite does. Basically, when I call removeFromSuperview, will it unload the UIImage used by my UIImageView and frees up all the memory used by that UIImage?

Also, can we say removeFromSuperview is equal to removeFromParentAndCleanUp:?

Thanks!


Solution

  • I think you're asking the wrong question. First, it's very easy to test which uses more memory (create one or the other, check memory in Instruments). But it shouldn't really matter (much) what kind of class displays an image on the screen, because the image (texture) itself will consume most of the memory anyway. I doubt you will see a significant difference between UIImageView and CCSprite when they both display the same 512x512 image because 99% of memory usage will be the texture.

    The main benefit of CCSprite is performance, specifically for realtime animations you need CCSprite. For user interfaces in menu screens the UIViews are just fine though.

    In addition cocos2d caches already loaded textures. I can't say the same for UIImageView. So CCSprite will be faster if you create and dismiss sprites using the same texture frequently.