Skip to content

runtime: clarify statement on g object memory lifetime #65843

@minkj1992

Description

@minkj1992

What is the URL of the page with the issue?

https://github.com/golang/go/blob/master/src/runtime/HACKING.md

What is your user agent?

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36

Screenshot

Screen Shot 2024-02-21 at 8 54 11 PM

What did you do?

read docs

What did you see happen?

All g, m, and p objects are heap allocated, but are never freed, so their memory remains type stable. As a result, the runtime can avoid write barriers in the depths of the scheduler.

What did you expect to see?

The statement "g objects are heap allocated, but are never freed, so their memory remains type stable" can be misleading. It may imply that the entire memory occupied by a goroutine, including its stack, remains allocated indefinitely.

To address this, proposes the following changes:

Update the documentation:

  • Clarify that the statement refers to the g object itself, not the goroutine's stack memory.

  • Explain that while the g object is never explicitly freed, its stack memory is eventually reclaimed by the garbage collector.

func gdestroy(gp *g) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.compiler/runtimeIssues related to the Go compiler and/or runtime.help wanted

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions