I am unsure about how to completely kill a node that uses graphics in cocos2d-iphone.
So what exactly do I mean? Well, for instance, I have a CCTMXTiledMap. It uses some textures, right? Well, I no longer need to use this tiled map, so I kill it, and I assume that such textures a killed as well, and memory is freed.
I am using [[CCTextureCache sharedTextureCache] dumpCachedTextureInfo]; to get info about the textures currently held in memory.
CCTMXTiledMap *map = [CCTMXTiledMap tiledMapWithTMXFile:@"myMap.tmx"];
[self addChild:map z:0];
[[CCTextureCache sharedTextureCache]
dumpCachedTextureInfo]; // I get 32MB usage.
[self removeChild:map cleanup:YES]; // I assume this will "kill" the map.
[[CCTextureCache sharedTextureCache]
dumpCachedTextureInfo]; // I STILL get 32MB usage
As you can see, removing the map from child doesn’t seem to truly kill the texture being used by it.
How exactly am I supposed to free memory then? I think that the same happens with CCSprites etc. Acoording to CCTextureCache, I just keep stacking memory until my app crashes.
Note: I know I could use something like [[CCTextureCache sharedTextureCache] removeAllTextures]; and clean everything up. But that doesn’t seem very efficient.
CCTextureCachewill only remove textures for which there exist NO references. I have not used theCTMXTileMapclass myself, but maybe there are objects in there that reference the texture. The same happens withCCSpriteBatchNode. You must first remove thespriteFrames, thenremoveUnusedTexturesfrom the cache, at which point the memory is reclaimed. Suggest you useremoveUnusedTexturesafter removing the map as child.I dont see an explicit cleanup in
CTMXTileMap, it is relying ondeallocto remove its objects that could reference the texture. Maybe (not certain about this), you should give a chance to the autorelease pool to release finally the map, before taking a measurement again.