From: Artur Signell Date: Thu, 19 Nov 2009 08:11:20 +0000 (+0000) Subject: Merged test case and fix for #3732 - "Programmatically closed applications remain... X-Git-Tag: 6.7.0.beta1~2284 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9a42b8955ec8c677a1c375cafc2a93ac4a5ae0aa;p=vaadin-framework.git Merged test case and fix for #3732 - "Programmatically closed applications remain in memory" from 6.1 svn changeset:9888/svn branch:6.2 --- diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java index 0300e26a94..692f30dc92 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java @@ -1928,8 +1928,6 @@ public abstract class AbstractApplicationServlet extends HttpServlet { if (session != null) { WebApplicationContext context = WebApplicationContext .getApplicationContext(session); - context.applicationToAjaxAppMgrMap.remove(application); - // FIXME: Move to WebApplicationContext context.removeApplication(application); } } diff --git a/src/com/vaadin/terminal/gwt/server/WebApplicationContext.java b/src/com/vaadin/terminal/gwt/server/WebApplicationContext.java index e49c95d905..2e114a38dc 100644 --- a/src/com/vaadin/terminal/gwt/server/WebApplicationContext.java +++ b/src/com/vaadin/terminal/gwt/server/WebApplicationContext.java @@ -193,6 +193,7 @@ public class WebApplicationContext implements ApplicationContext, protected void removeApplication(Application application) { applications.remove(application); + applicationToAjaxAppMgrMap.remove(application); } protected void addApplication(Application application) { @@ -216,7 +217,6 @@ public class WebApplicationContext implements ApplicationContext, while (!applications.isEmpty()) { final Application app = applications.iterator().next(); app.close(); - applicationToAjaxAppMgrMap.remove(app); removeApplication(app); } } catch (Exception e) { diff --git a/tests/src/com/vaadin/tests/application/ApplicationCloseTest.java b/tests/src/com/vaadin/tests/application/ApplicationCloseTest.java new file mode 100644 index 0000000000..0777f682ab --- /dev/null +++ b/tests/src/com/vaadin/tests/application/ApplicationCloseTest.java @@ -0,0 +1,70 @@ +package com.vaadin.tests.application; + +import com.vaadin.Application; +import com.vaadin.terminal.gwt.server.WebApplicationContext; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Label; +import com.vaadin.ui.Button.ClickEvent; + +public class ApplicationCloseTest extends TestBase { + + private String memoryConsumer; + + @Override + protected void setup() { + Label applications = new Label("Applications in session:
", + Label.CONTENT_XHTML); + for (Application a : ((WebApplicationContext) getContext()) + .getApplications()) { + applications.setValue(applications.getValue() + "App: " + a + + "
"); + } + applications.setValue(applications.getValue() + "

"); + + addComponent(applications); + Label thisApp = new Label("This applications: " + this); + Button close = new Button("Close this", new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + event.getButton().getApplication().close(); + } + }); + + StringBuilder sb = new StringBuilder(); + + // 100 bytes + String str = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"; + + int MB = 5; + for (int i = 0; i < MB * 10000; i++) { + sb.append(str); + } + + memoryConsumer = sb.toString(); + long totalUsage = Runtime.getRuntime().totalMemory(); + String totalUsageString = totalUsage / 1000 / 1000 + "MiB"; + Label memoryUsage = new Label( + "Using about " + + memoryConsumer.length() + / 1000 + / 1000 + + "MiB memory for this application.
Total memory usage reported as " + + totalUsageString + "
", Label.CONTENT_XHTML); + + addComponent(thisApp); + addComponent(memoryUsage); + addComponent(close); + } + + @Override + protected String getDescription() { + return "Click close to close the application and open a new one"; + } + + @Override + protected Integer getTicketNumber() { + return 3732; + } + +}