Author Topic: delete reference when disable or remove panel?  (Read 10193 times)

markofevil3

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 25
    • View Profile
delete reference when disable or remove panel?
« on: January 23, 2014, 06:57:39 AM »
I have 2 panels with some Widgets in each. When I remove one panel, all references still be keep if the other panel are still enable. Is there any way to release all reference of disabled panel?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: delete reference when disable or remove panel?
« Reply #1 on: January 23, 2014, 06:58:35 AM »
References to what?

markofevil3

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: delete reference when disable or remove panel?
« Reply #2 on: January 23, 2014, 07:14:29 AM »
the meshes reference. that's the reason when i call Resources.UnloadUnusedAssets, meshes memory size doesn't reduce. but if i disable all panels and call Resources.UnloadUnusedAssets, meshes memory size reduce

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: delete reference when disable or remove panel?
« Reply #3 on: January 23, 2014, 07:39:08 AM »
You need to yield return WaitUntilEndOfFrame() before calling UnloadUnusedAssets. Otherwise the panel's draw calls won't be destroyed yet.

markofevil3

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: delete reference when disable or remove panel?
« Reply #4 on: January 23, 2014, 08:49:29 AM »
I have recorded video.
https://dl.dropboxusercontent.com/u/86872228/Untitled.mov

This is the code for test

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Test : MonoBehaviour {
  5.         public GameObject go;
  6.         public UIPanel panel;
  7.         public UIPanel panel2;
  8.         private GameObject child;
  9.                
  10.         public void DeleteRows() {
  11.                 // Destroy();
  12.                 DestroyImmediate(panel2.gameObject);
  13.                
  14.                 StartCoroutine(UnloadResource());
  15.         }
  16.        
  17.         public void Create() {
  18.                 GameObject tmp;
  19.                 if (child != null) {
  20.                         for (int i = 0; i < 200; i++) {
  21.                                 tmp = Instantiate(go) as GameObject;
  22.                                 tmp.transform.parent = panel2.transform;
  23.                                 tmp.transform.localScale = Vector3.one;
  24.                         }
  25.                 }
  26.         }
  27.        
  28.         IEnumerator UnloadResource() {
  29.                 yield return new WaitForEndOfFrame();
  30.                 Resources.UnloadUnusedAssets();
  31.         }
  32. }

sgstester

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: delete reference when disable or remove panel?
« Reply #5 on: January 23, 2014, 08:57:36 AM »
 :(

sgstester

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: delete reference when disable or remove panel?
« Reply #6 on: January 23, 2014, 08:55:19 PM »
Hi there, no answer for this  question?

sgstester

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: delete reference when disable or remove panel?
« Reply #7 on: January 24, 2014, 03:57:58 AM »
 :-X

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: delete reference when disable or remove panel?
« Reply #8 on: January 24, 2014, 08:20:47 AM »
UnloadUnusedAssets unloads resource such as textures. Meshes are not a loaded resource. They get cleaned up by the garbage collector. You can make sure that NGUI destroys them by putting a Debug.Log inside UIDrawCall.OnDestroy.

P.S. Never use Instantiate. Use NGUITools.AddChild(parent, prefab). Look inside that function to figure out why.