incubator-flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Heidegger>
Subject JavaScript VS. Weak references
Date Tue, 07 Feb 2012 19:33:39 GMT
Hello List,

when I recently thought about a way to get AS3 code to JavaScript I got 
into a major concept problem related to Weak references. As maybe most 
of you know weak references are not supported by JavaScript. However: 
The current code using addEventListener() relies heavily on weak 
references to not come in trouble with memory leaks. This is also a big 
problem in other UI toolkits to my knowledge and other toolkits solve 
this using destructors or completely inverse control logic. For example 
in SWT you have to call:


after you stopped using your widget. The destructor-approach is in 
theory a lot faster than the weak reference approach because it doesn't 
rely on a garbage collector but it comes with a lot of code-noise. The 
other approach, to have it in a completely inverse control flow looks 
like this:

class Component implements IUIEventHandler {
    public function handleMouseEvent() {}

and handleMouseEvent is called from outside. All other approaches I know 
are just derivations of these two concepts. This means to me: Any use of 
weak Dictionaries and weak event listeners would need to vanish from the 
Flex SDK to actually make it portable.

I just wanted to point that out. It might be interesting to a few.

And related to that two questions:
  1) Does anyone know how browsers avoid memory leaks with 
addEventListener ?
  2) Would the Flex team be open to such a fundamental change in code-style?


View raw message