Author Topic: UIAtlas not unloaded after LoadLevel  (Read 13737 times)

Isamson

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 52
    • View Profile
UIAtlas not unloaded after LoadLevel
« on: August 15, 2014, 05:18:11 PM »
NGUI Version: 3.6.9
Unity version: 4.5.0f6 Pro

Hi Guys, we've been having memory leak problems with our project lately so we've decided to take a closer look at the Profiler. That's when we noticed that some UIAtlas are not unloaded. We've found this post: http://www.tasharen.com/forum/index.php?topic=9964.msg46832#msg46832 and decided to update NGUI in the hopes that this fix was added. It was but it didn't completely fixed our problem.

It would remove the UIAtlas only if the UIRoot was not a prefab. Since we instantiate the UIRoot at the loading of the scene, all our UI is made up of prefabs.

I thought it could be our project so I've re-created a new project from scratch using the NGUI example textures. This new project loop through 3 scenes and behaves the exact same way as our project. If you save the UIRoot as a prefab (blue) the UIAtlas is not unloaded. If the UIRoot prefab is gray, it gets removed at loading.

ArenMook: I have a testProject if you want it. PM me and I'll forward a download link.
Unity 4.5.3f
NGUI 3.7.0

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIAtlas not unloaded after LoadLevel
« Reply #1 on: August 16, 2014, 10:02:13 AM »
So if it's a prefab, it's kept in memory, and if it's not a prefab it gets released? Sounds like how Unity works with prefabs. Prefabs that are referenced somewhere are always kept in memory. Do you keep a reference to your prefab somewhere? Consider loading it by name instead via Resources.Load and make sure to set all references to this prefab to null before trying to unload it.

Isamson

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 52
    • View Profile
Re: UIAtlas not unloaded after LoadLevel
« Reply #2 on: August 18, 2014, 07:54:49 AM »
In the test project I've built, I don't instantiate the prefabs. They are simply dropped into the scene and saved there so I don't have to load them.

About our main project, I'm pretty sure the prefabs are assigned to null, but I'll check with the code team to make sure.
Unity 4.5.3f
NGUI 3.7.0

Isamson

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 52
    • View Profile
Re: UIAtlas not unloaded after LoadLevel
« Reply #3 on: August 19, 2014, 10:38:06 AM »
I've checked with the code team and they do set all prefabs references to null. I've PM you a link to my test project.
Unity 4.5.3f
NGUI 3.7.0

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIAtlas not unloaded after LoadLevel
« Reply #4 on: August 19, 2014, 10:51:25 AM »
Try calling UIDrawCall.ReleaseInactive() or ReleaseAll() before UnloadUnusedAssets().

Isamson

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 52
    • View Profile
Re: UIAtlas not unloaded after LoadLevel
« Reply #5 on: August 19, 2014, 01:33:21 PM »
It doesn't work, I still have the UIAtlas of the last loaded scene.
Unity 4.5.3f
NGUI 3.7.0

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIAtlas not unloaded after LoadLevel
« Reply #6 on: August 19, 2014, 01:55:29 PM »
So what's referencing it? Releasing all draw calls in NGUI flat out kills all references NGUI may have kept. Do you have some script referencing it?

Isamson

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 52
    • View Profile
Re: UIAtlas not unloaded after LoadLevel
« Reply #7 on: August 20, 2014, 07:39:54 AM »
Absolutely nothing that I can see.
I've modified the scenes of the testProject so that they only have 1 UIsprite within the scene. I've a single UIButton using only a UILabel as reference.
But when I switch from 1 scene to the next, I still have the UIAtlas loaded to memory.

Have you looked at the scene I've PMed you?
Unity 4.5.3f
NGUI 3.7.0

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIAtlas not unloaded after LoadLevel
« Reply #8 on: August 20, 2014, 05:12:56 PM »
I had a look at it, and a more detailed one just now. I added a ton of debug log statements and renamed all NGUI's materials created by the UIDrawCall. As far as I can tell, the references that remain actually remain somewhere in Unity rather than NGUI. I can see "scene3" texure still referenced by 1 item: "scene3" material. All NGUI-created materials have been renamed to have an "NGUI" prefix, which I still see referenced as "NGUI scene1 (Material)" for example. And yet "scene3" doesn't have an NGUI prefix. I don't know what still keeps a reference to it, but it doesn't appear to be NGUI.