Skip to content

Commit

Permalink
make sure to nil out excess capacity in l.visible slice
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Dec 9, 2023
1 parent ed5eb1c commit c31211e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions widget/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
}
}

0 comments on commit c31211e

Please sign in to comment.