flex-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Wright <twri...@yesco.com>
Subject Re: when to dispose of objects for garbage collection?
Date Thu, 06 Jun 2013 16:40:21 GMT
as an addenda here's the link I originally learned this from. There may be
some hidden secrets of gc that only the most elite know about, but for the
average developer, I'd guess this is, for the most part, what you'll need
to know.
go to slides 78 and 79
http://www.slideshare.net/rjowen/adobe-flex-component-lifecycle-presentation


On Thu, Jun 6, 2013 at 10:35 AM, Thomas Wright <twright@yesco.com> wrote:

> 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, <modjklist@comcast.net> 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: modjklist@comcast.net
>> To: users@flex.apache.org
>> 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
> twright@yesco.com
>
>


-- 
*Thomas Wright*
Software Engineer
Extension: 1054
Office: [801] 464.4600

Corporate Division
twright@yesco.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message