Skip to content

Memory leak in fontMetrics cache on desktop driver #4010

Closed
@longkui-clown

Description

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

  • When I use widget.NewMultiLineEntry with Entry.SetText() function as my app log area, there appera a memory leak
  • I tried to comment out the SetText function and the memory leak was relieved。

How to reproduce

  • Just run the code in this issue, there is no pprof code, and it can reproduce

Screenshots

No response

Example code


  • Code with pprof
package main

import (
	"fmt"
	"net/http"
	_ "net/http/pprof"
	"strings"
	"time"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/widget"
)

var logs = []string{}
var maxLogTake = 50

func main() {
	go func() {
		http.ListenAndServe("0.0.0.0:10000", nil)
	}()
	app := app.New()
	win := app.NewWindow("Hello World!")
	logArea := widget.NewMultiLineEntry()
	logArea.SetMinRowsVisible(15)

	content := container.NewVBox(
		container.NewHBox(
			widget.NewLabel("Click the button"),
			widget.NewButton("Log Test", func() {
				s_now := time.Now().Format("2006-01-02 15:04:05")
				for i := 0; i < 50; i++ {
					logs = append(logs, fmt.Sprintf("[Log](%v): %v", s_now, i))
				}

				logLen := len(logs)
				if logLen > maxLogTake {
					logs = append(logs[0:0], logs[logLen-maxLogTake:]...)
					logLen = maxLogTake
				}

				s_logs := strings.Join(logs, "\r\n")
				logArea.SetText(s_logs)
				logArea.CursorRow = logLen
				logArea.Refresh()
			}),
		),
		logArea,
	)

	win.Resize(fyne.NewSize(450, 320))
	win.SetContent(content)
	win.ShowAndRun()
}
  • click some times
    click1

  • click some times again
    click2

  • And can see the memory is increasing, I run again, and same

Fyne version

2.3.5

Go compiler version

1.20.2

Operating system and version

Windows 10

Additional Information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingoptimizationTickets that could help Fyne apps run faster

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions