Can someone help me identify when I need to dispose of an object, array, etc. 
in a typical Flex app? 

For example, suppose I have an app with several states and a TitleWindow. 

I know that if I declare a variable for a state, such as: 

<fx:Script> 
<![CDATA[ 
  ...
  private var myArr:Array;
  ...   
]]>
</fx:Script>

that when I no longer need this array (or object, etc.), I should set it to 
null to inform the garbage collector (GC) it's ready to be picked up. That's 
because, otherwise, this variable remains in memory, since the state persists 
throughout the life of the app.

But what if this state uses the following function:

<fx:Script> 
<![CDATA[ 
  private var summation:Number;
  ...   
  private function myFunc():void {
      var anotherArr:Array=[1,2,3,4,5]
      for (var i:int=0; i<anotherArr.length; i++)
        summation+=anotherArr[i];
  }
  ...
]]>
</fx:Script>

QUESTION 1: Do I need to manually null variable myArr2 at the end of function 
myFunc()? Or, will it be picked up automatically by the GC?

How about TitleWindows? 

QUESTION 2: If I open a TitleWindow (e.g. popup) that contains a DataGrid, do I 
need to manually null its data provider when I close the TitleWindow? Or, will 
it be picked up automatically by the GC? 

QUESTION 3: This last question also applies to a data provider for ComboBox, or 
an ArrayList, or an Array that is used in a TitleWindow -- do I need to null 
those as well upon closing the window? Or, will they be picked up automatically 
by the GC?

Thanks in advance for any comments.







Reply via email to