func X() {
x := 9
p := weak.Make(&x)
}
https://cs.opensource.google/go/go/+/refs/tags/go1.24.4:src/weak/pointer.go;l=67:
// Make creates a weak pointer from a pointer to some value of type T. func MakeT any Pointer[T] { // Explicitly force ptr to escape to the heap. <------ ???
Can the documentation clarify if weak.Make
makes objects that should be in the stack move to heap?
In the above snippet, will x
get moved to the heap? It is meant to only be used within X() and does not otherwise escape.
Comment From: randall77
It does currently escape its argument. That doesn't mean we want to promise that it does, or that it doesn't.
I don't think there's anything to change here. Escapiness is not an observable property of the language. (Except for library functions like testing.AllocsPerRun
).