diamondburned / gotk4

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

Why go4.org/unsafe/assume-no-moving-gc ? #101

Open s3rj1k opened 1 year ago

s3rj1k commented 1 year ago

Just out of curiosity why go4.org/unsafe/assume-no-moving-gc is needed and can it be removed at some point?

diamondburned commented 1 year ago

It's needed because package core/intern requires some uintptr hacks to replicate weak references, which was needed to prevent certain memory leaks from occuring. This assumes that the GC doesn't move pointers around when they're on the heap, which the package acts as a safe guard for.

If something like https://github.com/golang/go/issues/46787 gets added, we can probably get rid of assume-no-moving-gc altogether.

(As a side note, I'm not too confident that core/intern is doing its intended job right now. I'll have to look into it, but I think there was a regression that caused it to leak memory again. It's hard to figure this out when building the code after the slightest changes takes 20 minutes.)

s3rj1k commented 1 year ago

Thanks for explaining, a bit hesitated to use the binding with that dependency

s3rj1k commented 1 year ago

It's pretty much safe to close this issue, I would ask for a tagged release when gtk4 binding removes that unsafe dependency.

Thanks for your effort.

jclc commented 1 year ago

@diamondburned Go 1.21 was released today and it has a new type runtime.Pinner for this purpose. Maybe worth taking a look?