This blog article proposes the following example:
package db
func Open(path string, flags OpenFlags) (*Conn, error) {
// ...
runtime.SetFinalizer(conn, func(conn *Conn) {
panic("open db connection never closed")
})
return conn, nil
}
func (c *Conn) Close() {
// ...
runtime.SetFinalizer(conn, nil) // clear finalizer
}
Does this make sense, in order to ensure that some important resources are actually being closed ?