Sprite Atlas is loading multiple times in the memory

  • I’m having this problem where my sprite altases are being loaded into memory multiple times. This causes unnecessary memory usage and, on some of my devices that run android 6.0 with 1GB of ram, the app crashes. Mind you that i have some android devices with android 6.0 and 1GB that can run the app just fine, but i still have the same issue, very large memory consumption.

  • I tried profilling with the android studio profiller and with unity build-in profiler and the memory usage reported was the same.

  • The app that i am developing is using ~1000 sprites, so it makes sense to use sprite atlas, both for build size and memory consumption.

  • The app crashes right between two scenes, i am using Async load, and at it’s peak the memory usage reaches 0.53gb, which in my opinion for a small android build seems insane, right after that the app crashes on that device.

  • The method i am using for loading the sprite altases is with SpriteAtlas.GetSprites(), than i am storing the sprite in a static array, and i am making sure that SpriteAtlas.GetSprites() is never going to be called during the current game session. This, in my mind, removes any connection between sprite atlas and it’s contents. I am using this approach because i’ve seen that pulling sprite by sprite, using the SpriteAtlas.GetSprite() method, can be quite CPU and memory intensive in comparison with my current method.

  • Unfortunatley the unity documentation does not give any warning for bad practices so in this case i am unsure if am missing something in my programming, and it gets quite frustrating not knowing how should i approach this problem. Also i’ve seen that many other developers have this issue, but most of them have this problem in editor, where the profilling data is not coherent when it comes to a fizical device build.

  • This is really important since i will be publishing more games with the same theme, and i need to improve my tehnique in order for my apps to perform at their best both on high-end devices and low-end.

  • If there are any questions, about the code i used or about how the sprite altases are packed, i am more that happy to resolve this problem, not just for me but for any other developer that may come across this problem.

This was a something that i overlooked and for some of you that may come across this problem, this is completely normal. The reason behing the atlas being loaded multiple times, is that each atlas has a number of “pages”, and each of that page is being loaded into memory. There is no unecessary memory usage. Hope this helped some of you understand what happens, and is a bit sad that i had to find this out by testing not from the documenation.

just for the record, nowadays unity also prefixes the pages indexed, like


(also you can see in the references count column different values that suggests those objects are not the same)