Release memory of large dynamically loaded prefab

hi guys,

In order to optimize a mobile game, I decided to dynamically load my prefab assets, especially since there’s limited memory on some phones.

I loaded the prefab with cc.loader.loadRes and then decided when it’s not needed anymore, to release the memory using cc.loader.releaseAsset for the instantiated object and cc.loader.releaseRes for the prefab path. Looking at the memory of the cocos simulator, it does not seem that any memory is deallocated. Anyone has any idea?

EDIT: I also tried out cc.loader.releaseAll just to see if it helps, it doesnt

cc.loader.releaseAsset only removes the asset from loader, the memory holding is especially in textures, nodes, etc.

We do support auto release for a scene, but not yet for the prefab loaded dynamically.

In v1.2.2, if you click the scene asset in asset library, you will find a checkbox in the inspector panel: auto release resources, check it will permit the resources used in the scene to be released during scene transition.

Releasing prefab could also be possible, @Jare are you planning to implement it and how would the API looks like ?

About loader.releaseAssets, I think it could be improved but I’m not sure about it yet.

I am planning to implement something like: cc.loader.getDependents, to let you get all dependents but you should release by yourself because some of them may remain used in the scene or referenced in your scripts.

Thank you for the reply, @pandamicro , @jare

As it is now, we are relying heavily on a single scene, with not much transitions. Is there any other manual way for us to release the memory held by these prefabs after we have no use of them? Then for the time being, we can do it in our prefab script

I tried out dynamically loading a spriteframe from a jpg file. Am unable to release its memory as well, how do we invalidate the textures that we have loaded once we’re done with it?

For a specific texture, you need to remove all sprite frames that reference it, then do the following:

cc.textureCache.removeTexture(texture)

Now there is not such kind api, you can only use cc.loader.release or cc.textureCache.removeTexture(texture)

I see, thanks for the help guys, really appreciate it! =)

Hopefully we’ll get an api to help out with the memory releasing process.

Has anything changed on this?