Skip to content

Commit

Permalink
Clarify GC in structs example
Browse files Browse the repository at this point in the history
Fixes #550
  • Loading branch information
eliben committed Aug 14, 2024
1 parent 1a76037 commit bf195bf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 4 additions & 2 deletions examples/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ type person struct {

// `newPerson` constructs a new person struct with the given name.
func newPerson(name string) *person {
// You can safely return a pointer to local variable
// as a local variable will survive the scope of the function.
// Go is a garbage collected language; you can safely
// return a pointer to a local variable - it will only
// be cleaned up by the garbage collector when there
// are no active references to it.
p := person{name: name}
p.age = 42
return &p
Expand Down
4 changes: 2 additions & 2 deletions examples/structs/structs.hash
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
80344041b9268370bb6c73190afb1269e26f52fe
ex1J3oieEeo
b50c1756bf9a2ea7f8853f7f7cb7a61d5efebfc3
56SPo-L2nMN
8 changes: 5 additions & 3 deletions public/structs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bf195bf

Please sign in to comment.