flex-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From modjkl...@comcast.net
Subject when to dispose of objects for garbage collection?
Date Thu, 06 Jun 2013 15:52:05 GMT

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: 

  private var myArr:Array;

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:

  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++)

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.

View raw message