Author Topic: Possible Bug: Materials in BetterLists not correctly cleared  (Read 1996 times)

JeremyBurgess

  • Guest
Hi all,

We've observed an interesting bug, where an Atlas Material (and therefore the texture it referenced) was not being unloaded when invoking a Resources.UnloadUnusedAssets even though no objects remained which referred to the specified material.

After a fair bit of digging, we figured out that the material was added to the mChanged list inside UIPanel, and if the panel was never actually shown it was never removed. I added the following to UIPanel, which has resolved the issue:

   void OnDestroy()
   {
      OnDisable();
      mDrawCalls.Release();
      mChanged.Release();
#if OLD_UNITY
      mChildren.Release();
#endif
   }

My best guess is that this is a deficiency in the Mono runtime (or some other part of Unity responsible for object management), where the internals of the BetterList are not being correctly cleared/Garbage Collected, even when the associated BetterList should be gone. On reading the code, I can see no reason that this should happen, however it undeniably was happening for us.

Cheers,
Jeremy

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Possible Bug: Materials in BetterLists not correctly cleared
« Reply #1 on: July 04, 2013, 08:30:53 AM »
Interesting.. thanks for taking the time to look into it! I suggest just changing "Clear" calls to be "Release" instead in UIPanel.OnDisable.