Problem with cc.loader.release 1.4

Hi guys, am currently facing a problem with cc.loader.release.

Prior to 1.4 ( was using 1.3.2) , I was able to release the dependencies of prefab doing something like this :

const deps = cc.loader.getDependsRecursively(pathToPrefab);
cc.loader.release(deps);

However, after switching to 1.4, this does not seem to work anymore, the memory of the application does not seem to go down, even after forcibly calling cc.sys.garbageCollect. On 1.3.2, it was working perfectly. A a quick logging on the deps, shows that the path are somehow no longer relative? it is currently an absolute path, therefore a lot longer.

2 Likes

Update on the issue, a quick check on the ccloader source file shows that the for array types ( as returned by getdependsrecursively) actually delegates the release work to auto-release-utils 's autorelease method.

Looking at the line 34 of the auto-release-utils script, the release of an asset is dependent on it being set to true for auto release.

And as my prefabs were dynamically generated, their asset keys were not populated into the autoReleaseSettings of the loader, and therefore were not released at all. Adding the line cc.loader.setAutoReleaseRecursively(pathToPrefab, true) seems to have solved the problem.

Am not sure if this is an intended behaviour?

Url resource vs asset uuid logic is a bit confusing in Creator for now (or confused :slight_smile:)
As I see it, cc.loader.autoReleaseSettings exists for a sole purpose - so that resources you’ve loaded with cc.loader.loadRes won’t get automatically released on scene change. But it also produces some difficulties for manually releasing resources. One of them is what you’ve described - to release a prefab you need to manually release all dependencies (or mark them as auto-releaseable). On the other hand you need to somehow keep track of resources that have multiple dependants. For example when manually releasing a prefab and it’s dependencies you may accidentaly destroy a texture, that is used somewhere else in your scene

I see, although this isnt too obvious until I started digging into the source code itself. By default, dynamic loading disables it from the asset being release, maybe allow us to pass in a parameter instead, that way we wouldn’t need to call the method again after loading the prefab? Just a suggestion.