I stumbled upon this error report yesterday for Entities 0.17:
When I read it, I realized that my team has been suffering from this for a long time. Our editor keeps growing in memory, and we use a fair bit of SubScenes. I did not manage to find any info about this issue on the forums, and although it’s tagged for being fixed in 0.20 there was no publicly available solution so I took a little dive into it to see if I could find it myself.
It actually only took about fifteen minutes to find the cause by adding debug logs in Retain() and Release() for the BlobAssets. Here’s a short rundown:
- They were properly released when loading and unloading a SubScene.
- When disposing a world with loaded subscenes, the refcount stopped at 1 and they never got released.
- Comparing the callstacks for the Release calls from the two cases, I could identify which Release call was missing when disposing the world.
- The cause was that RetainBlobAssetsSystem was not releasing them, as it would have done had they lost their BlobAssetOwner which they normally do when scenes are unloaded.
- The solution was easy; I added an OnDestroy in the system that releases all BlobAssets who still had BlobAssetOwners.
- This screenshot shows the diff for the editor version of the system for those who are curious about what’s been modified.
For all of you using SubScenes that are suffering from it, I’ve attached the modified RetainBlobAssetsSystem.cs to this post. The issue and solution felt completely logical, and this all seems to work perfect. Feel free to replace your existing system if you’ve got a local copy of the entities package in your projects.
7452050–914294–RetainBlobAssetSystem.cs (5.75 KB)