diamondburned/gotk4

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

Opened this issue · 4 comments

s3rj1k commented

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

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 golang/go#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

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

s3rj1k commented

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

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