weak

Guided tour · Misc · pkg.go.dev →

Weak pointers — references that don't prevent GC (Go 1.24+). Build caches and maps that shouldn't keep values alive.

Usage

Make + Value

p := &User{Name: "Ada"}
w := weak.Make(p)

// later:
if u := w.Value(); u != nil {
    fmt.Println(u.Name) // still alive
} else {
    // the target was collected
}