diff options
author | Anna Koskinen <Ansku@users.noreply.github.com> | 2021-02-11 15:55:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-11 15:55:21 +0200 |
commit | f46362a731ce459d4afa7d79f60468ec72fda4ba (patch) | |
tree | 1d52c2d897082b1a0b7660dd142695b5eaa9ad44 | |
parent | be23b014866160cb4bc3af8ed808c6f749270dce (diff) | |
download | vaadin-framework-f46362a731ce459d4afa7d79f60468ec72fda4ba.tar.gz vaadin-framework-f46362a731ce459d4afa7d79f60468ec72fda4ba.zip |
Clear out ClientCache when UI is detached to prevent a minor memory leak (#12199)
* Clear out ClientCache when UI is detached to prevent a minor memory leak
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
-rw-r--r-- | server/src/main/java/com/vaadin/server/LegacyCommunicationManager.java | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/server/src/main/java/com/vaadin/server/LegacyCommunicationManager.java b/server/src/main/java/com/vaadin/server/LegacyCommunicationManager.java index 5cb90b428a..10ccb7726d 100644 --- a/server/src/main/java/com/vaadin/server/LegacyCommunicationManager.java +++ b/server/src/main/java/com/vaadin/server/LegacyCommunicationManager.java @@ -232,11 +232,26 @@ public class LegacyCommunicationManager implements Serializable { if (cache == null) { cache = new ClientCache(); uiToClientCache.put(uiId, cache); + uI.addDetachListener(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 |