I'm sure this must be really trivial but somehow I can't find the proper way ;)
So the situation is as follows:
1) I don't want to run into insufficient texture memory problems
2) Thus I create autoreleased scene for Tutorial
3) Tutorial should have a few full-screen images, some buttons, maybe some animations
a) Images for tutorial are completely separate from game images
4) I want to add tutorial images to a spriteframecache, so it's easier to use any animations etc
5) After checking tutorial - the scene should completely disappear from memory, including textures and spriteframes
Thus I do the following when creating a tutoial layer:
CCTexture2D * tex = [[CCTextureCache sharedTextureCache] addImage:@"tutorial_texture.png"];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"tutorial_texture.plist" texture:tex];
Pretty self explanatory - I add a texture to TextureCache and SpriteFrames to SpriteFrameCache
Now I create some sprites, animations, etc
After leaving the scene it is dealloced (autoreleased) but the texture and sprite frames stay in the caches
I hope all is clear till now ;)
Now the time to remove the textures... I tried the following methods in the onEnter scene of menuscene, after exiting the tutorial layer. This is correct place to do it, I already checked it
1) [[CCTextureCache sharedTextureCache] removeUnusedTextures]; - tutorial texture is NOT removed, because it is used in the sprite frames
2) [[CCTextureCache sharedTextureCache] removeTextureForKey:@"tutorial_texture.png"]; - again, NOT removed
3) `
[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
[[CCTextureCache sharedTextureCache] removeUnusedTextures];
`
sprite frames are released and so is the texture. BUT ! all the other unused sprite frames are also immediately released, obviously not something I would like...
So how should I do it really ? Note that I only want to remove one large texture and all sprite frames that refer to it, nothing more
There is a function to add spriteframes from .plist file for a specific texture -addSpriteFramesWithFile:(NSString*)plist texture:(CCTexture2D*)texture
I really think there should be additional function which would do the very reverse - removeSpriteFramesFromFile:(NSString*) plist