Is there a way to release unmanaged resources when a Go struct is collected?

Viewed 843

I have a pointer to a C type wrapped by a Go struct, like so:

type Wrapper struct {
    unmanaged *C.my_c_type
}

The C type, in turn, has the following functions:

my_c_type* make_c_type();
void free_c_type(my_c_type *ct);

Is there a way that I can ensure that free_c_type is called whenever a Wrapper instance is finalized?

1 Answers
Related