summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnna Koskinen <Ansku@users.noreply.github.com>2021-02-15 09:03:00 +0200
committerGitHub <noreply@github.com>2021-02-15 09:03:00 +0200
commitadca7a508783d1c7c849660b02260120696ef0f2 (patch)
treef6c944782a361db3967d5b0a9aac34a42afa5a84
parentebfc693f2d74965aebc6773ee696153441a822e5 (diff)
downloadvaadin-framework-adca7a508783d1c7c849660b02260120696ef0f2.tar.gz
vaadin-framework-adca7a508783d1c7c849660b02260120696ef0f2.zip
Clear out ClientCache when UI is detached to prevent a minor memory leak (#12200)
Implemented with a listener rather than direct call from UI.detach() in order to avoid new public API, since the whole feature has been marked for removal. This doesn't yet prevent the cache or the type map from getting slightly bloated during the UI's lifetime. See: #3705 Cherry-picked from: #12199
-rw-r--r--server/src/main/java/com/vaadin/server/LegacyCommunicationManager.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/server/src/main/java/com/vaadin/server/LegacyCommunicationManager.java b/server/src/main/java/com/vaadin/server/LegacyCommunicationManager.java
index eabca9fc09..dff4187637 100644
--- a/server/src/main/java/com/vaadin/server/LegacyCommunicationManager.java
+++ b/server/src/main/java/com/vaadin/server/LegacyCommunicationManager.java
@@ -29,6 +29,8 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import com.vaadin.server.ClientConnector.ConnectorErrorEvent;
+import com.vaadin.server.ClientConnector.DetachEvent;
+import com.vaadin.server.ClientConnector.DetachListener;
import com.vaadin.shared.ApplicationConstants;
import com.vaadin.shared.JavaScriptConnectorState;
import com.vaadin.shared.communication.SharedState;
@@ -189,17 +191,37 @@ public class LegacyCommunicationManager implements Serializable {
* @deprecated As of 7.1. See #11410.
*/
@Deprecated
- public ClientCache getClientCache(UI uI) {
+ public ClientCache getClientCache(final UI uI) {
Integer uiId = Integer.valueOf(uI.getUIId());
ClientCache cache = uiToClientCache.get(uiId);
if (cache == null) {
cache = new ClientCache();
uiToClientCache.put(uiId, cache);
+ uI.addDetachListener(new DetachListener() {
+ @Override
+ public void detach(DetachEvent event) {
+ removeClientCache(uI);
+ }
+ });
}
return cache;
}
/**
+ * Clear out client cache for the given UI. This should be called when the
+ * UI is detached and the cache becomes obsolete.
+ *
+ * @param uI
+ * the UI whose client cache should be removed
+ * @deprecated because this cleanup is only needed for a deprecated feature
+ */
+ @Deprecated
+ private void removeClientCache(UI uI) {
+ Integer uiId = Integer.valueOf(uI.getUIId());
+ uiToClientCache.remove(uiId);
+ }
+
+ /**
* Checks if the connector is visible in context. For Components,
* {@link #isComponentVisibleToClient(Component)} is used. For other types
* of connectors, the contextual visibility of its first Component ancestor