0

I am loading a Cocos2d Scene that contains almost 700 png Images and even if I run this scene directly from Xcode I receive a Memory Warning message along with a long list of some of my Image names in the console..

I am properly deallocating them in dealloc but when I come again on this scene this time my game crashes during loading my half of the Images

Is this the problem of loading so much textures at once or problematic code?

How should I handle loading so many images and do proper memory management to avoid this crash?

4

1 回答 1

2

700 png images? Hmmm. Ok, I like those games.

Let's assume each image is "only" 128x128 pixels. Each texture consumes 64 KB (128 times 128 times 4 Bytes). Total of 45 MB memory used for 700 such textures.

If your textures are twice that or even more, KA-BOOM!

Keep in mind that the file size has nothing to do with texture memory. The files may total a few megabytes in the file system. But that's because they're compressed. Textures created from PNG files however are not compressed.

What you can do:

  • use texture atlases
  • reduce color depth of textures to 16 Bit
  • use compressed PVR format

TexturePacker will help you with these tasks.

于 2012-09-14T17:48:24.530 回答