When the user eventually closes the browser, if there's any leaked memory, does it get returned to the system, or does it remain leaked thereafter?
----- Original Message ----- From: "Alex Harui" <[email protected]> To: [email protected] Sent: Thursday, June 6, 2013 10:12:20 AM Subject: Re: when to dispose of objects for garbage collection? Answers in-line, but I'm not sure what "CREATED in" really means. Does it mean defined in a single MXML file? On 6/6/13 9:03 AM, "[email protected]" <[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? This particular function will not leak the array (note that it re-creates the array every time it gets called which is inefficient). But if you did: private function myFunc():void { var anotherArr:Array=[1,2,3,4,5]; var someFunction:Function = function() { } and someFunction is assigned as an event listener or other callback, then anotherArr is on the scope chain and will be held onto until someFunction is no longer referenced, which could be long after myFunc() ended. > >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? It depends on who else has references to the dataProvider. The DG has a listener on the dataProvider, so that means the dataProvider has a reference to the DG in order to call a function in the DG when the dataProvider changes. If the dataProvider is part of some global model, then the DG will be held in memory by the dataProvider. If the dataProvider is only referenced by the DG or other things in the TitleWindow, then it will all go away together. > > >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? See #2.
