Skip to content

weak: Documentation: clarification if weak.Make() moves objects from stack to heap #74298

Closed
@pjebs

Description

@pjebs
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 Make[T any](ptr *T) 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions