How to free up atlas textures of UGUI in memory?

From Profiler I find that the atlas textures are never freed.(Even though I invoke Resources.UnloadUnusedAssets() manually)
And after multiple times of loading UI, Textures of memory will be larger and larger, and then crashed.

e.g
In scene1, I use atlas A,B,C.
Then I go to scene2, I only use altas C,D,E
But from Profiler, I find A & B still in the memory.

I’m not sure if this is a kind of GC strategy. But in Android platform, expecially for some devices which memory less than 1024MB, UGUI takes a lot of memory.

Please help

Are you profiling in the editor or on the actual target device?

I find it that you can never really trust the results from the editor… They even wrote that right inside the profiler window…

I’m using an actual target device.

I created a new project for testing. And I find something interestring.
In scene1, I use atlas A.
In scene2, I use atlas B.

If I goto scene2 when ALL the image gameobjects in scene1 are active, atlasA will be freed.
BUT if even one of the gameobjects is deactive, altasA will always in the memory !

So I basically determined that this is a UGUI official bug.

Did you use the profiler’s detailed memory mode? it allows you to see which objects are loaded into memory, and also who references them.

This is extremely helpful in scenarios such as this one, when you’re trying to determine why a certain texture is still held in memory.

BTW - do you know if this issue can also be seen while profiling in the editor?

I did.
The detail shows the atlas is reference by “ManagedStaticReferences”.

And I know this issue can also be seen while profiling in the editor.
Everytime I check the profiler, I restart Unity and make sure the profiler is exactly right.

And thanks for your replying :slight_smile:

ManagedStaticReferences – somewhere in your code, you are holding a static reference to a texture, or indirectly, to an object that holds the texture via some reference chain… You should first try to analyze whats holds references to any texture from that atlas.

And I’m also sure ALL the static reference and reference chain to atlas has been freed up.

In my test project, there’s not even one line of code. But the atlas still in the memory after I goto another scene.

Can you share the test project so i could also play with it ?