I'm fairly sure that unless you've created any sort of event listener attached to that particular object, or any sort of inherently necessary link to that object from a parent object, that GC should collect once it's removed from execution. However, to be safe and make sure GC collects on its next pass, setting a variable to null ensures collection. So in theory, that would be best practice, but in practice, that's not always the best way to do something. For question 2, I'm fairly sure you don't, since the dataprovider is only a reference, there is not any inherent dependence on the object that contains the data that is used as a dataprovider. Again, you may wish to double check that. For the third question, no, you don't need to null anything that's a child. Once you orphan those objects by clearing the window, GC immediately collects at its next pass. I'm still not 100% sure whether or not there's a gotcha here, but I'm fairly confident that this is how things are done.
On Thu, Jun 6, 2013 at 10:03 AM, <[email protected]> wrote: > I should have mentioned regarding question 2 and 3, that the DataGrid, > ComboBox, etc., used by the TitleWindow was CREATED in the TitleWindow, and > is not used external to the TitleWindow. The questions being whether the > TitleWindow automatically cleans up these variables for GC, or requires me > to null them first... > > ----- Original Message ----- > From: [email protected] > To: [email protected] > Sent: Thursday, June 6, 2013 8:52:05 AM > Subject: when to dispose of objects for garbage collection? > > > 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. > > > > > > > > -- *Thomas Wright* Software Engineer Extension: 1054 Office: [801] 464.4600 Corporate Division [email protected]
