I have an MVP GWT 2.5.1 app using version 1.1.1 of gwt-visualization. My view has two Button
s and a VerticalPanel
(accessed by the presenter as display.getPanel()
). One button adds a PieChart
to the VerticalPanel
, the the other removes it. The presenter holds the PieChart
reference as a Widget
so that it knows when it has been added/removed. It is initialized to null
.
I checked chrome's dev tools to ensure that the add/remove code wasn't creating a DOM leak. But after the PieChart
was removed, its elements were left behind in a detached DOM tree, all color coded red. When I tried the same add/remove code with a Label
instead of a PieChart
, no detached DOM tree remained after removal.
My questions is: am I doing something wrong when either adding or removing the PieChart
? Perhaps gwt-visualization has some other method of handling this that I am not aware of, but my google-fu is unable to produce an answer.
The presenter add/remove code is below:
display.getAddChartButton().addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (widget == null) {
Runnable onLoadCallback = new Runnable() {
public void run() {
PieChart content = new PieChart(createTable(), createOptions());
// Label content = new Label("Content");
display.getPanel().add(content);
widget = content;
}
};
VisualizationUtils.loadVisualizationApi(onLoadCallback, PieChart.PACKAGE);
}
}
});
display.getRemoveChartButton().addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (widget != null) {
display.getPanel().remove(widget);
widget = null;
}
}
});
private AbstractDataTable createTable() {
DataTable data = DataTable.create();
data.addColumn(ColumnType.STRING, "Task");
data.addColumn(ColumnType.NUMBER, "Hours per Day");
data.addRows(2);
data.setValue(0, 0, "Work");
data.setValue(0, 1, 14);
data.setValue(1, 0, "Sleep");
data.setValue(1, 1, 10);
return data;
}
private Options createOptions() {
Options options = Options.create();
options.setWidth(400);
options.setHeight(240);
options.setTitle("My Daily Activities");
return options;
}
I've traced the memory leak to the Google Chart API itself. The team is aware of memory leak issues.