2
votes

I am building an app that uses Cocos2d to create a map of content (technically a big Tree in the graph theory sense). Each node is represented by a sprite with it's own texture, with the leaf nodes all having a second "button pressed" texture. In addition, some of the nodes are PNG animations. I have one sprite sheet containing the 130 or so node textures, and 3 other sprite sheets for the animations. All in all those 4 files add up to only about 18.4 MB.

If I run the app and DON'T run the cocos2d part (i.e. Never launch the framework at all and therefore never load the textures) the app runs at around 10 MB. When I load Cocos2d and those sprite sheets, the memory shoots up past 90 MB.

All my research seems to say I am doing things in the most efficient way possible, but with the memory usage already so high I get a lot of memory related crashes on iPad 1.

Is this normal for cocos2d? Since the images themselves aren't so large, is it using so much memory because of the number of sprites? Are there ways to bring the memory footprint down? I am at a loss, and very much under the gun...

1

1 Answers

3
votes

It turns out that the efficiency you achieve by packing the sprites together into big sprite sheets is measured in rendering time, not in memory saved. No matter in a UIImage or into an OpenGL framework like Cocos2d, when you load an image the amount of memory it takes up is width x height x bytes per pixel. So a 2048x2048 png image takes up 2048x2048x4 bytes in memory (12 MB).

To keep memory down in this case I simply have to load things as needed, and unload them as soon as they are not needed. Now the trick is finding out where and when to load, so the user never sees a stutter. FUN!