From f5c5060fa237c4e852bb003c1f6a02c8a47f19ad Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Thu, 24 Sep 2020 15:46:25 +0300 Subject: [PATCH] fix: prevent possible memory leak (#1102) Prevent possible memory leak when e.g. Grid is removed from layout as data provider listener is not explicitly removed. --- .../java/com/vaadin/flow/component/grid/Grid.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/Grid.java b/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/Grid.java index 564590ab..358c14a4 100755 --- a/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/Grid.java +++ b/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/Grid.java @@ -41,6 +41,7 @@ import com.vaadin.flow.component.ComponentEvent; import com.vaadin.flow.component.ComponentEventListener; import com.vaadin.flow.component.ComponentUtil; +import com.vaadin.flow.component.DetachEvent; import com.vaadin.flow.component.Focusable; import com.vaadin.flow.component.HasElement; import com.vaadin.flow.component.HasSize; @@ -3149,6 +3150,18 @@ public void sort(List> order) { protected void onAttach(AttachEvent attachEvent) { super.onAttach(attachEvent); updateClientSideSorterIndicators(sortOrder); + if (getDataProvider() != null && dataProviderChangeRegistration == null) { + handleDataProviderChange(getDataProvider()); + } + } + + @Override + protected void onDetach(DetachEvent detachEvent) { + if (dataProviderChangeRegistration != null) { + dataProviderChangeRegistration.remove(); + dataProviderChangeRegistration = null; + } + super.onDetach(detachEvent); } private void setSortOrder(List> order,