There is a runtime.SetFinalizer, but it is not guaranteed to be run, anytime. The most idiomatic and safe solution is to have a Close() method on the Go side, which frees the C side. You may even add a Finalizer that panics if Close haven't been called before...
tokers a következőt írta (2020. november 23., hétfő, 4:17:18 UTC+1): > There is a runtime.SetFinalizer function. > > On Sunday, November 22, 2020 at 8:13:22 PM UTC+8 Sean wrote: > >> I am writing a Golang wrapper for OpenAL-Soft. >> I need to create some buffers. These operations are happening on the >> OpenAL-Soft side (So C functions). I am loading PCM data into buffers. >> >> Can I set up a trigger mechanism like "x.__del__" as in Python? >> >> I can set the garbage collector to follow some objects. >> But I have to call some C functions (alDeleteBuffers) to delete buffers >> in OpenAL. >> >> I want garbage collector to run this function while deleting the object. >> >> Is this possible? >> >> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b71a4582-523d-448c-b404-050c84f932ecn%40googlegroups.com.