- Home /
HD SD atlas switch: Unload unused
Hello,
I am making a 2D game and need to switch texture atlas SD to HD if screen resolution is high. Ok works great with my own script.
At startup all Image sprite are in SD resolution. If I switch to HD then all sprite are HD, ok. But in the profiler I can see that Ref Count on SD atlas version stay.
I find all object in UI that have UI.Image component. I assign the sprite reference to the one in HD.
if(img.sprite != null)
{
name = img.sprite.name;
img.sprite = null;
// assign sprite to renderer
sprite = ResourceManager.Instance.GetSprite(name);
if (sprite != null)
img.sprite = sprite;
}
I have added to the end of my script
Resources.UnloadUnusedAssets(); System.GC.Collect();
I am wondering if I need to do something else? Why SD texture atlas ref count is not decremented?
Thank you.
Answer by TobyKaos · Jul 03, 2015 at 02:12 PM
I will reply to me. Time between moderator read my answer have been benefic.
Then I have forgetten to release Sprite in my Sprite manager. Then one reference on each stay in memory.
Just now some ref that stay in memory if I do not force unload with a Resources.UnloadAsset(sprite.texture) at first launch of my game. (Sprite Manager empty).
Maybe an order of execution of Awake class. I will search in deep. Else I will first index my texture in my Sprite Manager and release unusefull at particular resolution.