From c31211ec555ee5bb993c3868a82b2dffae9735f6 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Sat, 9 Dec 2023 15:58:10 -0800 Subject: [PATCH] make sure to nil out excess capacity in l.visible slice --- widget/list.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/widget/list.go b/widget/list.go index 5c24d0444c..80c63b63fd 100644 --- a/widget/list.go +++ b/widget/list.go @@ -664,6 +664,7 @@ func (l *listLayout) updateList(newOnly bool) { return } + oldVisibleLen := len(l.visible) l.visible = l.visible[:0] oldChildrenLen := len(l.children) l.children = l.children[:0] @@ -690,6 +691,7 @@ func (l *listLayout) updateList(newOnly bool) { l.children = append(l.children, c) } l.nilOldSliceData(l.children, len(l.children), oldChildrenLen) + l.nilOldVisibleSliceData(l.visible, len(l.visible), oldVisibleLen) for _, wasVis := range wasVisible { if _, ok := l.searchVisible(l.visible, wasVis.id); !ok { @@ -781,3 +783,12 @@ func (l *listLayout) nilOldSliceData(objs []fyne.CanvasObject, len, oldLen int) } } } + +func (l *listLayout) nilOldVisibleSliceData(objs []itemAndID, len, oldLen int) { + if oldLen > len { + objs = objs[:oldLen] // gain view into old data + for i := len; i < oldLen; i++ { + objs[i].item = nil + } + } +}