From 0c7cbc73dba97ad0b95cb11f4b4eabb37046fe61 Mon Sep 17 00:00:00 2001 From: Pekka Hyvönen Date: Fri, 14 Mar 2014 16:17:27 +0200 Subject: Fixes a memory leak on IE8 in LayoutManagerIE8 (#12688) Change-Id: Ieae3b1d82e92fadf5ab517c1c878fc82bcc0ecbd --- client/src/com/vaadin/client/LayoutManager.java | 9 +++++++++ client/src/com/vaadin/client/LayoutManagerIE8.java | 15 +++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'client/src') diff --git a/client/src/com/vaadin/client/LayoutManager.java b/client/src/com/vaadin/client/LayoutManager.java index 1ced003146..5b27031a29 100644 --- a/client/src/com/vaadin/client/LayoutManager.java +++ b/client/src/com/vaadin/client/LayoutManager.java @@ -74,6 +74,15 @@ public class LayoutManager { this.connection = connection; } + /** + * Returns the application connection for this layout manager. + * + * @return connection + */ + protected ApplicationConnection getConnection() { + return connection; + } + /** * Gets the layout manager associated with the given * {@link ApplicationConnection}. diff --git a/client/src/com/vaadin/client/LayoutManagerIE8.java b/client/src/com/vaadin/client/LayoutManagerIE8.java index a692f126a2..97e3059a22 100644 --- a/client/src/com/vaadin/client/LayoutManagerIE8.java +++ b/client/src/com/vaadin/client/LayoutManagerIE8.java @@ -21,6 +21,7 @@ import java.util.Map; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; +import com.google.gwt.dom.client.Node; import com.google.gwt.user.client.ui.RootPanel; /** @@ -39,6 +40,12 @@ public class LayoutManagerIE8 extends LayoutManager { private Map measuredSizes = new HashMap(); + // this method is needed to test for memory leaks (see + // LayoutMemoryUsageIE8ExtensionConnector) but can be private + private int getMeasuredSizesMapSize() { + return measuredSizes.size(); + } + @Override protected void setMeasuredSize(Element element, MeasuredSize measuredSize) { if (measuredSize != null) { @@ -62,12 +69,16 @@ public class LayoutManagerIE8 extends LayoutManager { @Override protected void cleanMeasuredSizes() { Profiler.enter("LayoutManager.cleanMeasuredSizes"); - Document document = RootPanel.get().getElement().getOwnerDocument(); + + // #12688: IE8 was leaking memory when adding&removing components. + // Uses IE specific logic to figure if an element has been removed from + // DOM or not. For removed elements the measured size is discarded. + Node rootNode = Document.get().getBody(); Iterator i = measuredSizes.keySet().iterator(); while (i.hasNext()) { Element e = i.next(); - if (e.getOwnerDocument() != document) { + if (!rootNode.isOrHasChild(e)) { i.remove(); } } -- cgit v1.2.3