Author Topic: Atlas Leak  (Read 2195 times)

myprabath

  • Guest
Atlas Leak
« on: July 17, 2013, 10:09:28 AM »
I do have atlas leak in my current project.
so all the Atlases are inside memory after its loaded.
i have scene specific atlases so a given scene have specific Altus.

I found few references initial search and clean up. but still i can find the atlases are not  getting release soon after scene been unloaded.

now what I'm tying is force to unload texture from UI atlas material. Its worked and now i can not see the atlus texture in memory but that makes a UISprites and other UIWidget derived object gray or white. but if i deactivate and enable(from inspector) they are getting refreshed.

so can some one help me here.

Unload texture by,
  1. UnityEngine.Object[] Objs1 = Resources.FindObjectsOfTypeAll(typeof(UIAtlas));
  2. List<UIAtlas> totalAtluses = new List<UIAtlas>();
  3. foreach(UnityEngine.Object tempObject in Objs1)
  4. {
  5.         UIAtlas atlus = tempObject as UIAtlas;
  6.         Resources.UnloadAsset(atlus.spriteMaterial.mainTexture);
  7. }
  8.  

Reload textures By,
  1. Object loadedAtlusTexture = Resources.LoadAssetAtPath("/Atlases/"+atlusName, typeof(Texture2D));
  2. atlusObject.spriteMaterial.mainTexture = (Texture2D)loadedAtlusTexture;
  3. atl.MarkAsDirty();
  4.  

I do have latest NGUI

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Atlas Leak
« Reply #1 on: July 18, 2013, 04:17:15 AM »
Before unloading the texture, set atlas.spriteMaterial.mainTexture to null first. You can't unload things that are referenced.