I recently upgraded to VS2012 and try my in dev game out on the new WP8 emulators but was dismayed to find out the emulator now crashes and throws an out of memory exception during my sprite loading procedure (funnily, it still works in WP7 emulators and on my WP7).
Regardless of whether the problem is the emulator or not, I want to get a clear understanding of how I should be managing memory in the game.
My game consists of a character whom has 4 or more different animations. Each animation consists of 4 to 7 frames. On top of that, the character has up to 8 stackable visualization modifications (eg eye type, nose type, hair type, clothes type). Pre memory issue, I preloaded all textures for each animation frame and customization and created animate action out of them. The game then plays animations using the customizations applied to that current character.
I re-looked at this implementation when I received the out of memory exceptions and have started playing with RenderTexture instead, so instead of pre loading all possible textures, it on loads textures needed for the character, renders them onto a single texture, from which the animation is built. This means the animations use 1/8th of the sprites they were before. I thought this would solve my issue, but it hasn't.
Here's a snippet of my code:
var characterTexture = CCRenderTexture.Create((int)width, (int)height);
characterTexture.BeginWithClear(0, 0, 0, 0);
// stamp a body onto my texture
var bodySprite = MethodToCreateSpecificSprite();
bodySprite.Position = centerPoint;
bodySprite.Visit();
bodySprite.Cleanup();
bodySprite = null;
// stamp eyes, nose, mouth, clothes, etc...
characterTexture.End();
As you can see, I'm calling CleanUp and setting the sprite to null in the hope of releasing the memory, though I don't believe this is the right way, nor does it seem to work...
I also tried using SharedTextureCache to load textures before Stamping my texture out, and then clearing the SharedTextureCache with:
CCTextureCache.SharedTextureCache.RemoveAllTextures();
But this didn't have an effect either. Any tips on what I'm not doing?
I used VS to do a memory profile of the emulation causing the crash.
Both WP7.1 and WP8 emulators peak at about 150mb of usage. WP8 crashes and throws an out of memory exception.
Each customisation/frame is 15kb at the most. Lets say there are 8 layers of customisation = 120kb but I render then onto one texture which I would assume is only 15kb again.
Each animation is 8 frames at the most. That's 15kb for 1 texture, or 960kb for 8 textures of customisation.
There are 4 animation sets. That's 60Kb for 4 sets of 1 texture, or 3.75MB for 4 sets of 8 textures of customisation.
So even if its storing every layer, its 3.75MB.... no where near the 150mb breaking point my profiler seems to suggest :(
WP 7.1 Memory Profile (max 150MB)
WP8 Memory Profile (max 150MB and crashes)