Skip to content

Commit

Permalink
Pull in mem leak fix from fyne-io/pull/4768
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Apr 13, 2024
1 parent e8b6f75 commit d9a397b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions widget/richtext.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,29 @@ func (t *RichText) cachedSegmentVisual(seg RichTextSegment, offset int) fyne.Can
return vis
}

func (t *RichText) cleanVisualCache() {
if len(t.visualCache) <= len(t.Segments) {
return
}
var deletingSegs []RichTextSegment
for seg1 := range t.visualCache {
found := false
for _, seg2 := range t.Segments {
if seg1 == seg2 {
found = true
break
}
}
if !found {
// cached segment is not currently in t.Segments, clear it
deletingSegs = append(deletingSegs, seg1)
}
}
for _, seg := range deletingSegs {
delete(t.visualCache, seg)
}
}

// insertAt inserts the text at the specified position
func (t *RichText) insertAt(pos int, runes string) {
index := 0
Expand Down Expand Up @@ -712,6 +735,7 @@ func (r *textRenderer) Refresh() {

r.Layout(r.obj.Size())
canvas.Refresh(r.obj.super())
r.obj.cleanVisualCache()
}

func (r *textRenderer) layoutRow(texts []fyne.CanvasObject, align fyne.TextAlign, xPos, yPos, lineWidth float32) (float32, float32) {
Expand Down

0 comments on commit d9a397b

Please sign in to comment.