Author Topic: Memory problem with Flash  (Read 1625 times)

Stoysky

  • Guest
Memory problem with Flash
« on: August 24, 2012, 04:06:25 AM »
We are developing a game with Unity3d and recently we switched from native Unity3d UI components to NGUI 2.1.4 . Unfortunately after the switch we are experiencing some problems when we compile and run our game on Flash. When we start the game the memory usage keeps increasing  even if the game is idle – i. e. the player does not do anything and non of the “main” game objects is created. The used memory increases with more than 1GB in less than 10 minutes! Without NGUI (we removed all NGUI game objects from our scene) and under the same circumstances (i.e. idle game) the memory usage remains stable and no increase is observed.

Our short investigation (using TheMiner Flash profiler) shows that when NGUI is used the UINode.HasChanged() method is called extremely often and this lead to some copying of memory internally in Unity Engine code. When we commented (just for the sake of testing) the body of this method out, the memory usage increase rate seemed to get lower. Except for UINode.HasChanged()  there are some other often used NGUI component methods which lead to this memory copying in Unity Engine.

Could you please give us some advise or directions to overcome this problem? We like very much NGUI and we would like to use it.

Thank you in advance.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 270
  • -Receive: 1132
  • Posts: 21,846
  • Toronto, Canada
    • View Profile
Re: Memory problem with Flash
« Reply #1 on: August 24, 2012, 05:16:46 AM »
Sounds like another bug in Flash and you should let Unity know. There is nothing happening in HasChanged function other than a couple of inequality checks:

  1. #if UNITY_3_5
  2.         bool isActive = mGo.active && (widget == null || (widget.enabled && widget.color.a > 0.001f));
  3. #else
  4.         bool isActive = mGo.activeSelf && (widget == null || (widget.enabled && widget.color.a > 0.001f));
  5. #endif
  6.  
  7.         if (lastActive != isActive || (isActive &&
  8.                 (lastPos != trans.localPosition ||
  9.                  lastRot != trans.localRotation ||
  10.                  lastScale != trans.localScale)))
  11.         {
  12.                 lastActive = isActive;
  13.                 lastPos = trans.localPosition;
  14.                 lastRot = trans.localRotation;
  15.                 lastScale = trans.localScale;
  16.                 return true;
  17.         }