Is anyone using finalizers to detect resource leaks?

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 ?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.