You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by Marcus Wilkinson <wi...@gmail.com> on 2013/11/26 14:22:24 UTC

Aiding the garbage collector

So we have a tabbed application where a memory leak of about 5MB doesn't
seem to be collected properly. I am looking for an easy way out to help out
the GC. After using the flash builder profiler it seems that lots of
bindings amongst visual components and other things are still hanging
around after the tab is closed. All of these things belonged to the tab but
as far as I am aware, there are no other references to the original view.

I understand that nulling out references can help the garbage collector
identify which objects can be collected since it doesn't need to consider
one large 'island' before it can collect.

I found this tool which looks like it has potential, but unfortunately is
specific to Flex 3:
https://code.google.com/p/flex-uicomponent-cleaner-and-gc-initiator/source/browse/trunk/com/tommyb/util/gc/UIComponentCleaner.as

Does anyone know of or have anything like this for Flex 4?

Marcus

Re: Aiding the garbage collector

Posted by Alex Harui <ah...@adobe.com>.

On 11/26/13 12:24 PM, "Carlos Rovira" <ca...@codeoscopic.com>
wrote:

>Hi Alex,
>
>I think bindings through MXML still leave some links that need of this
>kind
>of tool? I remember that some years ago we needed to use a similar code to
>remove all bindings in one of our MDI applications when we was about to
>close a window module, cleaning all the stuff generate in that module. If
>not we end with the module still hanging on in memory. This was by the
>time
>Flex 4.0 was shipping...
There could be issues destroying sub-instances of an MXML document.  I
think the binding system expects that the entire MXML document will be
instantiated and "released".

-Alex


Re: Aiding the garbage collector

Posted by Carlos Rovira <ca...@codeoscopic.com>.
Hi Alex,

I think bindings through MXML still leave some links that need of this kind
of tool? I remember that some years ago we needed to use a similar code to
remove all bindings in one of our MDI applications when we was about to
close a window module, cleaning all the stuff generate in that module. If
not we end with the module still hanging on in memory. This was by the time
Flex 4.0 was shipping...


2013/11/26 Alex Harui <ah...@adobe.com>

> Interesting.  I thought we got all of the leaks out of binding.  Do you
> know what actually had to get cleaned to clean up the memory?
>
> -Alex
>
> On 11/26/13 7:24 AM, "Marcus Wilkinson" <wi...@gmail.com> wrote:
>
> >So just to follow up. I hacked up the UIComponentCleaner so that is will
> >work with IVisualElementContainers. The code is far from perfect, but it
> >seems to work for now:
> >http://pastebin.com/cxcSWGNK
> >
> >I intend to do a cleaner version of this when I have time and to host it
> >in
> >GitHub, but i'm just using pastebin for now.
> >Note, that patching the following files is required:
> >
> >
> >   - mx.binding::FunctionReturnWatcher - Change the private "document",
> >    "parameterFunction", "parentObj" and "functionGetter" properties to
> >   properties to public scope.
> >   - mx.binding::PropertyWatcher - Change the private "parentObj" Object
> >   and protected "propertyGetter" Function properties to public scope.
> >   - mx.binding::RepeaterComponentWatcher - Change the private "clones"
> >Array
> >   property to public scope.
> >   - mx.binding::Watcher - Change the protected "listeners" and "children"
> >   - Array properties to public scope.
> >
> >Hope someone finds this useful,
> >
> >Marcus
> >
> >
> >On 26 November 2013 13:22, Marcus Wilkinson
> ><wi...@gmail.com>wrote:
> >
> >> So we have a tabbed application where a memory leak of about 5MB doesn't
> >> seem to be collected properly. I am looking for an easy way out to help
> >>out
> >> the GC. After using the flash builder profiler it seems that lots of
> >> bindings amongst visual components and other things are still hanging
> >> around after the tab is closed. All of these things belonged to the tab
> >>but
> >> as far as I am aware, there are no other references to the original
> >>view.
> >>
> >> I understand that nulling out references can help the garbage collector
> >> identify which objects can be collected since it doesn't need to
> >>consider
> >> one large 'island' before it can collect.
> >>
> >> I found this tool which looks like it has potential, but unfortunately
> >>is
> >> specific to Flex 3:
> >>
> >>
> >>
> https://code.google.com/p/flex-uicomponent-cleaner-and-gc-initiator/sourc
> >>e/browse/trunk/com/tommyb/util/gc/UIComponentCleaner.as
> >>
> >> Does anyone know of or have anything like this for Flex 4?
> >>
> >> Marcus
> >>
>
>


-- 
Carlos Rovira
Director de TecnologĂ­a
M: +34 607 22 60 05
F:  +34 912 94 80 80
http://www.codeoscopic.com
http://www.directwriter.es
http://www.avant2.es

Re: Aiding the garbage collector

Posted by Alex Harui <ah...@adobe.com>.
Interesting.  I thought we got all of the leaks out of binding.  Do you
know what actually had to get cleaned to clean up the memory?

-Alex

On 11/26/13 7:24 AM, "Marcus Wilkinson" <wi...@gmail.com> wrote:

>So just to follow up. I hacked up the UIComponentCleaner so that is will
>work with IVisualElementContainers. The code is far from perfect, but it
>seems to work for now:
>http://pastebin.com/cxcSWGNK
>
>I intend to do a cleaner version of this when I have time and to host it
>in
>GitHub, but i'm just using pastebin for now.
>Note, that patching the following files is required:
>
>
>   - mx.binding::FunctionReturnWatcher - Change the private "document",
>    "parameterFunction", "parentObj" and "functionGetter" properties to
>   properties to public scope.
>   - mx.binding::PropertyWatcher - Change the private "parentObj" Object
>   and protected "propertyGetter" Function properties to public scope.
>   - mx.binding::RepeaterComponentWatcher - Change the private "clones"
>Array
>   property to public scope.
>   - mx.binding::Watcher - Change the protected "listeners" and "children"
>   - Array properties to public scope.
>
>Hope someone finds this useful,
>
>Marcus
>
>
>On 26 November 2013 13:22, Marcus Wilkinson
><wi...@gmail.com>wrote:
>
>> So we have a tabbed application where a memory leak of about 5MB doesn't
>> seem to be collected properly. I am looking for an easy way out to help
>>out
>> the GC. After using the flash builder profiler it seems that lots of
>> bindings amongst visual components and other things are still hanging
>> around after the tab is closed. All of these things belonged to the tab
>>but
>> as far as I am aware, there are no other references to the original
>>view.
>>
>> I understand that nulling out references can help the garbage collector
>> identify which objects can be collected since it doesn't need to
>>consider
>> one large 'island' before it can collect.
>>
>> I found this tool which looks like it has potential, but unfortunately
>>is
>> specific to Flex 3:
>>
>> 
>>https://code.google.com/p/flex-uicomponent-cleaner-and-gc-initiator/sourc
>>e/browse/trunk/com/tommyb/util/gc/UIComponentCleaner.as
>>
>> Does anyone know of or have anything like this for Flex 4?
>>
>> Marcus
>>


Re: Aiding the garbage collector

Posted by Marcus Wilkinson <wi...@gmail.com>.
So just to follow up. I hacked up the UIComponentCleaner so that is will
work with IVisualElementContainers. The code is far from perfect, but it
seems to work for now:
http://pastebin.com/cxcSWGNK

I intend to do a cleaner version of this when I have time and to host it in
GitHub, but i'm just using pastebin for now.
Note, that patching the following files is required:


   - mx.binding::FunctionReturnWatcher - Change the private "document",
    "parameterFunction", "parentObj" and "functionGetter" properties to
   properties to public scope.
   - mx.binding::PropertyWatcher - Change the private "parentObj" Object
   and protected "propertyGetter" Function properties to public scope.
   - mx.binding::RepeaterComponentWatcher - Change the private "clones" Array
   property to public scope.
   - mx.binding::Watcher - Change the protected "listeners" and "children"
   - Array properties to public scope.

Hope someone finds this useful,

Marcus


On 26 November 2013 13:22, Marcus Wilkinson <wi...@gmail.com>wrote:

> So we have a tabbed application where a memory leak of about 5MB doesn't
> seem to be collected properly. I am looking for an easy way out to help out
> the GC. After using the flash builder profiler it seems that lots of
> bindings amongst visual components and other things are still hanging
> around after the tab is closed. All of these things belonged to the tab but
> as far as I am aware, there are no other references to the original view.
>
> I understand that nulling out references can help the garbage collector
> identify which objects can be collected since it doesn't need to consider
> one large 'island' before it can collect.
>
> I found this tool which looks like it has potential, but unfortunately is
> specific to Flex 3:
>
> https://code.google.com/p/flex-uicomponent-cleaner-and-gc-initiator/source/browse/trunk/com/tommyb/util/gc/UIComponentCleaner.as
>
> Does anyone know of or have anything like this for Flex 4?
>
> Marcus
>