Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eval does not release memory/ has a memory leak #1678

Open
andig opened this issue Jan 6, 2025 · 1 comment
Open

Eval does not release memory/ has a memory leak #1678

andig opened this issue Jan 6, 2025 · 1 comment

Comments

@andig
Copy link

andig commented Jan 6, 2025

The following program sample.go triggers an unexpected result

package main

import (
	"fmt"
	"runtime"
	"runtime/debug"
	"time"

	"github.com/traefik/yaegi/interp"
)

func main() {
	vm := interp.New(interp.Options{})
	if _, err := vm.Eval(`var price float64`); err != nil {
		panic(err)
	}

	for {
		if _, err := vm.Eval(`price = 1.0`); err != nil {
			panic(err)
		}

		debug.FreeOSMemory()

		var stats runtime.MemStats
		runtime.ReadMemStats(&stats)
		fmt.Println(stats.Alloc)

		time.Sleep(10 * time.Millisecond)
	}
}

Expected result

// steady memory consumption

Got

// growing memory consumption

Yaegi Version

0.16.1

Additional Notes

Running an Eval() against a VM without allocating new variables leaks memory. If no allocation happens within the VM, the memory profile of the VM should remain stable.

This seems to make the Yaegi VM unsuitable for long-running purposes.

@andig
Copy link
Author

andig commented Jan 6, 2025

It looks as if the memory consumption comes from growing interp.roots (https://github.com/traefik/yaegi/blob/master/interp/ast.go#L938). Is this something that could be eliminated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant