diamondburned / gotk4

Autogenerated GTK4 bindings for Go
GNU Affero General Public License v3.0
461 stars 20 forks source link

gtk.Picture memory leak #144

Open iamdrq opened 3 weeks ago

iamdrq commented 3 weeks ago

First.Thanks for your work.

This is a test demo:

package main

import (
    "github.com/diamondburned/gotk4/pkg/gdk/v4"
    "github.com/diamondburned/gotk4/pkg/gio/v2"
    "github.com/diamondburned/gotk4/pkg/glib/v2"
    "github.com/diamondburned/gotk4/pkg/gtk/v4"
    "github.com/disintegration/imaging"
    "log"
    "os"
    "runtime"
    "time"
)

func main() {
    application := gtk.NewApplication("com.demo", gio.ApplicationFlagsNone)
    application.Connect("activate", func() {
        log.Println("application activate")
        w := gtk.NewWindow()
        w.SetVisible(true)
        img := gtk.NewPicture()
        img.SetVisible(true)
        w.SetChild(img)
        application.AddWindow(w)
        go func() {
            for range time.Tick(time.Second) {
                src, _ := imaging.Open("a.png")
                dst := imaging.Blur(src, 1)
                glib.IdleAdd(func() {
                    data := glib.NewBytes(dst.Pix)
                    text := gdk.NewMemoryTexture(dst.Bounds().Dx(), dst.Bounds().Dy(), gdk.MemoryR8G8B8A8, data, uint(dst.Stride))
                    img.SetPaintable(text)
                    runtime.GC()
                })
            }
        }()
    })
    os.Exit(application.Run(os.Args))
}

Run this that memory always increate.

jgillich commented 1 week ago

Likely the same as #126. Was fixed at some point but that was rolled back due to crashes