Hello Guest

Author Topic: Texture Atlas does not get unloaded / has strange reference  (Read 7817 times)

Arnold

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 32
  • Create something you love!
    • View Profile
Hi!

With Unity 5 i have finally accsess to the profiler with which i'm trying to optimize my game.
Now i'm not an expert on how memory management in Unity/Tk2s works but i have this strange issue
where i can not unload one specific atlas! I'm 100% sure that there are no GameObject referencing this atlas
in my scene anymore before i call Resources.UnloadUnusedAssets().

But the Profiler still says the Atlas references the original Prefab? Which is strange since i don't understand
why it would do that instead of only linking the atlas to acutal sprites within the Scene?

Maybe i'm getting something wrong here but how is that possible and how can i unload that freaking atlas :D?


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Texture Atlas does not get unloaded / has strange reference
« Reply #1 on: March 17, 2015, 02:08:08 pm »
Are you checking this in an actual runtime build? An editor profile will not be representative of what will happen in game.

Arnold

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 32
  • Create something you love!
    • View Profile
Re: Texture Atlas does not get unloaded / has strange reference
« Reply #2 on: March 17, 2015, 03:13:55 pm »
Aha ok interesting. Would a standalone build be enough to be sure or do i need to build for iOS to actually see what happens? As far as i understand i can't attach the profiler to xcode somehow right?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Texture Atlas does not get unloaded / has strange reference
« Reply #3 on: March 17, 2015, 03:30:44 pm »
I would test on the actual platform, but standalone is usually way better than editor.
You can attach the profiler to a running build if you tick the profile option (not tried this in Unity5 though, YMMV)

Arnold

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 32
  • Create something you love!
    • View Profile
Re: Texture Atlas does not get unloaded / has strange reference
« Reply #4 on: March 17, 2015, 03:34:37 pm »
Ok i've attached it to the iPhone and it's the same problem. There are exactly 9 references which are the 9 parts my prefab is made of. But there is no GameObject of this prefab existing in the scene anymore.

https://dl.dropboxusercontent.com/u/1291801/iphone5.png[/img]]

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Texture Atlas does not get unloaded / has strange reference
« Reply #5 on: March 17, 2015, 03:52:54 pm »
So Unity thinks that prefab is still there, or is referenced by something.
I don't really have any recommendations on debugging this - you'll need to figure out why your sprite prefab is not being unloaded. The place to start would be that object I guess, and track it down from there? It just needs to be a reference to the prefab in some other object for it to retain this, so it could be hidden away somewhere...

Arnold

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 32
  • Create something you love!
    • View Profile
Re: Texture Atlas does not get unloaded / has strange reference
« Reply #6 on: March 17, 2015, 03:54:58 pm »
Interesting so "any" other object in the scene which could hold a reference to it would be able to block the unload. Even if the original GameObject is destroyed?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Texture Atlas does not get unloaded / has strange reference
« Reply #7 on: March 17, 2015, 03:58:29 pm »
Any object that holds a reference will block an unload.

Arnold

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 32
  • Create something you love!
    • View Profile
Re: Texture Atlas does not get unloaded / has strange reference
« Reply #8 on: March 17, 2015, 04:00:07 pm »
Ok thanks for the quick help, will try to find the issue - i have a guess already but lets see.

***EDIT

Ok, i found the problem. One of my GameObjects was referenced in a pooling script where it was linked to the GameObject Prefab.
I also found out that the Profiler is pretty correct when it comes to textures loaded. It pretty much is the same in the Editor and on the Device.
« Last Edit: March 18, 2015, 04:46:28 pm by Arnold »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Texture Atlas does not get unloaded / has strange reference
« Reply #9 on: March 21, 2015, 11:16:15 pm »
Awesome! Glad you found it :)

Also, I've learnt the hard way not to trust the profiler in the editor. I've seen it lie far too many times... its great for a quick overview but if you need to verify something do it on the platform.

Arnold

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 32
  • Create something you love!
    • View Profile
Re: Texture Atlas does not get unloaded / has strange reference
« Reply #10 on: April 27, 2016, 09:19:06 am »
Just googled my own Topic...

Here's another gotcha for any future googles:

If you use a singleton and don't use

Code: [Select]
void OnDestroy()
{
    Instance = null;
}

Texture references to prefabs etc. are stored forever and you can never free this memory.