-
Notifications
You must be signed in to change notification settings - Fork 22
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
C objects are not destroyed when the GC frees the Go object #2
Comments
Yeah, almost all memory management in go-wlroots has to be done manually right now. Fixing this is a bit more complicated than it seems. Right now, all Go structs that wrap C pointers are always passed by value. I did it that way to prevent having multiple different Go pointers for the same C pointer. To use go-wlroots/wlroots/listener.go Lines 3 to 18 in b00418e
I'm not sure if there's a better way to do this. Every solution I can think of is ugly and complicated. |
Am I guessing this correctly that, in this solution, the Go object pointer would Also, as a side note, once it's decided that Go structs that wrap C values type Backend struct {
_ [0]sync.Mutex
p *C.struct_wlr_backend
} which will allow the linter to warn the user when |
This results in memory leaks.
The fix is to use
runtime.SetFinalizer
(see e.g. https://github.com/emersion/go-tsm/blob/master/vte.go#L47).The text was updated successfully, but these errors were encountered: