Two very good articles here for anyone who wants to learn more about GC in Flash Player
[1] http://www.digitalprimates.net/author/codeslinger/2011/10/11/talking-trash-an-overview-of-player-gc/ [2] http://www.adobe.com/devnet/flashplayer/articles/garbage_collection.html (Check out the interactive simulation on this page as well) Thanks, Om On Thu, Jun 6, 2013 at 11:36 AM, Romain KELIFA <[email protected]>wrote: > From what I know, most of the things you create via MXML is automatically > handled (from GC point of view) by the framework. > > However, everything you create via pure AS3 must be handled manually, > that's why it can be a good practice to implement a dispose() method in > your components 'abstract' classes (wired on FlexEvent.REMOVE), at least to > remove all classes event listeners and manual bindings (which is to say, > created via BindingUtils use). > > Last but not least, every instances created inside a method (I mean locale > variables, not class members) won't stay in memory once method has finished > its execution, provided there's no listener or binding attached to it. > > I hope these infos will help you :) > Le 6 juin 2013 20:19, <[email protected]> a écrit : > > > 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. > > > > >
