Weird cache manager behaviour

Hi. I’m still using cocosd2x 3.16
I’m getting a following problem.
Sometimes I can see a bunch of log lines like this:

**cocos2d: TextureCache: removing unused texture: /private/var/containers/Bundle/Application/0C5D804B-55B5-4B6C-97E8-63DCFAEA6242/**

**cocos2d: TextureCache: removing unused texture: /private/var/containers/Bundle/Application/0C5D804B-55B5-4B6C-97E8-63DCFAEA6242/**

**cocos2d: TextureCache: removing unused texture: /private/var/containers/Bundle/Application/0C5D804B-55B5-4B6C-97E8-63DCFAEA6242/**

sometimes right after that i receive a crash:

Sometimes it causes inconsistent look:

Can someone help me understand what am I doing wrong and how can I avoid this?
I’m using standard cache routine at the start of game:

        function(result, count, loadedCount) {
        function() {
            this.ready = true;

this.resources contains all assets used in the project.

If you search for that in the source, you’ll end up here:

void TextureCache::removeUnusedTextures()
    for (auto it = _textures.cbegin(); it != _textures.cend(); /* nothing */) {
        Texture2D *tex = it->second;
        if (tex->getReferenceCount() == 1) {
            CCLOG("cocos2d: TextureCache: removing unused texture: %s", it->first.c_str());

            it = _textures.erase(it);
        else {


Put a breakpoint on that to find out where it’s getting called from, and then you should be able to figure out why it’s happening.

Thanks for the answer, I tracked down where it comes from.
As I suspected it is due to low memory reason.

Can I avoid this somehow? Or any other way to handle it?

Better resource management would help you. Based on your initial post, I assume you are not using sprite sheets, so if that is the case, then you should consider that option.

Also, loading all the resources at the start of the game is probably not a good idea, since you’ll have graphics in memory that you aren’t actually using, or only using in specific scenes. If you’re running into memory issues, then perhaps it’s a better idea to only load what you need, when you need it. Things like UI graphic you can put on a sprite sheet, and keep in memory, assuming the UI resources are shared between scenes.

First of all, I’m using sprite sheets, also I optimized texture format to pvr3ccz and RGBA4444 mode.
And the second I read in cocos2d documentation here and it shouldn’t causes assets missing im memory issue. If it doesn’t find an assets on cache directory it tries to load it again. Do I understand right?

the only solution coming to my mind is to cache texture related to certain screen right before runing this screen scene. but I’m not sure whether this method would be helpful.

You could check the routine that should be reloading the graphics to figure out why it isn’t, assuming the references are still in the cache.