Hi there,
We have a project with loads of sprite atlases, each is built into its own bundle using Addressables.
At some point during the build (the WriteSerializedFiles task) the editor crashes because the system is out of memory.
If I hack into the code and insert a good old Resources.UnloadUnusedAsset()
between each bundle, the memory remains steady until it reaches the SpriteAtlas bundles. Then the memory keeps going up, and it seems due to the (CachedSpriteAtlasRuntimeData) super object, indirectly referenced by the SpriteAtlasDatabase (which isn’t touched by Resources.UnloadUnusedAsset()
).
Each atlas is kept in memory until the editor crashes.
Is there any API that could allow us to free that unused atlas memory during the build process?
We would like to be able to build without upgrading our hardware.
I already posted this message in the addressables sub-category but it remained unanswered.
Thanks
I’ll allow myself to bump this thread.
This makes our project un-buildable, with no guarantee that if we upgrade our hardware the issue won’t come back as the project keeps growing.
Thanks
I ran into the exact same issue (atlases leaking during a build script). I ended up resolving it using a couple of techniques. One, I did as much work with SpriteAtlas and Sprite GUIDs as I could. This moved my leak further down in my code, but I still ran into issues where I had a loop where I loaded all of the packables from each atlas in order to get their GUID. I was releasing the atlas, but I had to also release the sprites, otherwise the SpriteAtlasDatabase would retain a permanent lock on the textures. I’m pretty sure that in my original code I was unloading the sprites later, but it was still leaking. I think part of the confusion was that I had multiple leaks, and fixing one wasn’t resolving the problem. It didn’t help that the memory profiler was pointing the finger at SpriteAtlasDatabase and not the sprite instances.
var existingPackables = atlas.GetPackables().Select(sprite => {
if (sprite == null) return null;
AssetDatabase.TryGetGUIDAndLocalFileIdentifier(sprite, out string guid, out long localId);
// NOTE If this isn't called here the texture for the sprite is not released
Resources.UnloadAsset(sprite);
return guid;
}).Where(o => o != null).ToArray();