So I’m running in to some serious memory issues. Basically here is what I’m trying to achieve.
Purge device memory after each level.
Most of the memory I’m using is from Textures.
I’ve got several (5-10) very large (2048x2048) PNG spritesheets in the spriteframecache. I’ve tried various functions to get rid of all the texture data.
Calling those functions will only release the reference held by the cache, if you still have instances of Sprite or ImageView in your scene, or if you’ve called retain on Texture2D instances directly in custom types, you must ensure they are all released/destroyed before the texture itself will cleanup.
It might be useful to add a debug log in one of those cache functions to find out what textures are persisting. For example:
@almax27 So if I understand you correctly, any sprite or texture pointer (Sprite*) that is created from the SpriteFrameCache must be destroyed separately? What function would I call on the sprite object? Would it be
sprite->Release();
Not exactly, if you have called retain on anything that is or uses a Texture2D instance yourself you must call release before it is freed. But for node derivatives like Sprite (which internally use the TextureCache) that you’ve instanced using ::create() and added to your scene via ::addChild() you must ensure they are removed from the scene. This is because children of a node have been retained by their parent and will not be released until they are removed or the parent is destroyed.
For a better understanding of how all this works please read this page, and take a look at the cocos2d-x source code for the types you make use of.
I do have a basic understanding of auto release pool and how it’s modelled on the ios system of course. I just didn’t realize I had to call removeChild for every sprite even if it wasn’t retained. This helps a lot. Hopefully my memory will deallocate properly now. Thanks.