i noticed that the texture is not added into memory like filenames. When i try to free unused memory, using: Director::getInstance()–>getTextureCache()->emoveUnusedTextures(); i believe that the memory from this custom textures is not freed.
Also i noticed that sometimes a key called “cc_2x2_white_image”.
However, i still can’t understand how custom textures are maanged in memory if they dont have a key like filenames. Mayve they are released automatically when the sprite is removed vs filenames which remain in shared texture cache?
@zhangxm i tried to reproduce my case in HelloWorld. Here is the code:
bool HelloWorld::init(){
if ( !Scene::init() ) return false;
Sprite *spriteWithFilename = Sprite::create("HelloWorld.png");
this->addChild(spriteWithFilename);
const int loops = 1000;
auto callbackAddChilds = CallFunc::create([this,spriteWithFilename,loops](){
for (int i=0; i<loops; i++){
auto rt = RenderTexture::create(100,100,Texture2D::PixelFormat::RGBA8888);
rt->beginWithClear(0, 0, 0, 0);
spriteWithFilename->visit();
rt->end();
spriteWithFilename->setTexture(rt->getSprite()->getTexture());
}
});
this->runAction( Sequence::create(DelayTime::create(3),callbackAddChilds, NULL));
return true;
}
What i did, is that i run the code for 10, 100 and 1000 loops. I assume 2 things will happen:
rt will be released automatically at the end of the current loop.
When i set the texture of an existing sprite in the scene, i expect the previously set texture to be released.
Therefore, all of these loops should ended up in the same memory. However, every time we call setTexture, it seems that memory goes up without the previous texture being released. This test was done in a real device. Am I missing something?
I also tried to remove the sprite from the scene and then nullify it to see if that will clear all memory but it seems that only the last texture is cleared.
I hope so ) As code indicated, you release previous here. I just thought it was strange if xcode indicated that memory was used to not indicate memory was freed.