GWT dev mode memory leak with simple use case

2014-01-30 Thread Phineas Gage
Any widget that is added to the DOM seems to never get garbage collected 
when using dev mode, even if it's removed from the DOM. Here is the sample 
source, with just two classes:

public class GwtMemEntryPoint implements EntryPoint {

@Override
public void onModuleLoad() {
for (int i = 0; i  3; i++) {
RootLayoutPanel.get().clear();
RootLayoutPanel.get().add(new LeakyWidget());
}
}

}

public final class LeakyWidget extends Label {

private static int count = 0;

public LeakyWidget() {
setText(Hello Leaky Widget  + (++count));
}

}

*Configuration*
- OS/X 10.9.1
- Eclipse Kepler SR1
- Eclipse Memory Analyzer Tool 1.3.1
- GWT 2.5.1
- Firefox 26.0
- JDK 1.7.0_51

*To reproduce*
- Run the above application
- Run GC manually (I used jconsole for this)
- Run Eclipse Memory Analyzer to get a heap dump 
(http://www.eclipse.org/mat/)
- View the number of instances of LeakyWidget in the heap dump

*What I'd expect*
- The number of instances of LeakyWidget to be 1, which is the only widget 
that hasn't yet been removed from the DOM, the one currently displayed

*What actually happens*
- The number of instances of LeakyWidget is still 3. If you keep reloading 
the sample, the number of widgets keeps increasing. They are released when 
you quit Firefox.

*Question*
So why is this the case, and is it by design? I would like a way to look 
for memory leaks in my code in dev mode without compiling to JS and using a 
JS debugger, but if this is not possible, and if this leak is by design, it 
would be good to know.

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.


Re: GWT dev mode memory leak with simple use case

2014-01-30 Thread Jens
FireFox plugin currently has a memory 
leak: 
https://groups.google.com/forum/#!searchin/google-web-toolkit-contributors/firefox/google-web-toolkit-contributors/9YUqQ3vzwV4/3mUd4Y9u8GAJ

But even if you find memory leaks in Java it does not mean that its a 
JavaScript memory leak. Also you might have a JavaScript leak thats not a 
Java leak. So at the end you want to compile your app and use chrome dev 
tools to look for memory leaks. One memory leak that is very easy to spot 
in chrome dev tools are detached DOM trees. These are DOM trees that are 
still referenced by JavaScript code although they are not attached to the 
document. If you see large numbers of them then it is likely that you 
clear() some widgets somewhere but JS still has a reference to them.
But be aware that not all detached DOM trees are memory leaks. If you have 
a widget / DOM element that you only insert into the DOM on certain 
conditions and otherwise is held in memory then its probably fine (e.g. 
show either this or that view but both views are already created and held 
in memory).

-- J.

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.


Re: GWT dev mode memory leak with simple use case

2014-01-30 Thread Phineas Gage
OK, that's clear. This simple use case does not leak per the JavaScript 
profiler in Chrome (note to future readers to compile with at least Output 
style: Pretty). I was originally tracking down a leak in my own code, but 
it turns out that doesn't leak in JS either.

I suppose that in super dev mode you wouldn't be dealing with this, because 
you'd be using your debugger and profiler strictly in JS.

Thanks for the response.

On Thursday, January 30, 2014 1:33:19 PM UTC+1, Jens wrote:

 FireFox plugin currently has a memory leak: 
 https://groups.google.com/forum/#!searchin/google-web-toolkit-contributors/firefox/google-web-toolkit-contributors/9YUqQ3vzwV4/3mUd4Y9u8GAJ

 But even if you find memory leaks in Java it does not mean that its a 
 JavaScript memory leak. Also you might have a JavaScript leak thats not a 
 Java leak. So at the end you want to compile your app and use chrome dev 
 tools to look for memory leaks. One memory leak that is very easy to spot 
 in chrome dev tools are detached DOM trees. These are DOM trees that are 
 still referenced by JavaScript code although they are not attached to the 
 document. If you see large numbers of them then it is likely that you 
 clear() some widgets somewhere but JS still has a reference to them.
 But be aware that not all detached DOM trees are memory leaks. If you have 
 a widget / DOM element that you only insert into the DOM on certain 
 conditions and otherwise is held in memory then its probably fine (e.g. 
 show either this or that view but both views are already created and held 
 in memory).

 -- J.



-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.