Hi Thomas,

The problem with memory leaks in browser is that it's sometimes hard
to understand where they come from. Here, we are writting a little
piece of code that will be transformed (replacement of @...()) and
incorporated into a more complexe code. I don't want to look at the
generated code to check if leaks are possibile. So, I always use the
syntax I give so that I'm sure there will not be any leak... It's some
type of discipline.

Using a static method to inject the code seems to me being the same
thing...

Olivier

On 23 mar, 00:07, Thomas Broyer <[email protected]> wrote:
> On 22 mar, 23:42, Olivier Monaco <[email protected]> wrote:
>
>
>
>
>
> > The "call" method of a JavaScript function allows you to call it with
> > a differente "this". Then, using "$wnd.js_callback.call(otherObject)",
> > the "this" variable reference otherObject. So the glue is:
>
> > var that = this;
> > $wnd.js_callback = function() {
> >     $entry(@mypackage.MyClass::MyMethod()).call(that);
>
> > }
>
> > When "js_callback" will be called, MyMethod is called on "that", the
> > JavaScript object representing the MyClass instance. Finally, to avoid
> > memory leaks of closure:
>
> > $wnd.js_callback = (function(obj) {
> >     return function() {
> >         $entry(@mypackage.MyClass::MyMethod()).call(obj);
> >     };
>
> > })(this);
>
> ... or more simply:
> var that = this;
> $wnd.js_callback = $entry(function() { that.
> @mypackage.MyClass::MyMethod()(); });
>
> (this is what I should have written previously, sorry for the buggy
> code)
>
> As for the leak, are you sure there really is one once the code is
> translated into JS? would it be better if the "inject" method were a
> static one with the instance being passed as an argument (no use of
> the "this"keyword within JSNI)?

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to