Thursday, January 30, 2014

GWT dev mode memory leak with simple use case

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 {

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


public final class LeakyWidget extends Label {

    private static int count = 0;

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


- 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 (
- 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.

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
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment