From bf195bf4ebb89c0dd70e21cab0c8244cd4130f87 Mon Sep 17 00:00:00 2001
From: Eli Bendersky
Date: Wed, 14 Aug 2024 08:14:52 -0700
Subject: [PATCH] Clarify GC in structs example
Fixes #550
---
examples/structs/structs.go | 6 ++++--
examples/structs/structs.hash | 4 ++--
public/structs | 8 +++++---
3 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/examples/structs/structs.go b/examples/structs/structs.go
index d56c0aa60..f06b61dca 100644
--- a/examples/structs/structs.go
+++ b/examples/structs/structs.go
@@ -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
diff --git a/examples/structs/structs.hash b/examples/structs/structs.hash
index 372123828..da28967d4 100644
--- a/examples/structs/structs.hash
+++ b/examples/structs/structs.hash
@@ -1,2 +1,2 @@
-80344041b9268370bb6c73190afb1269e26f52fe
-ex1J3oieEeo
+b50c1756bf9a2ea7f8853f7f7cb7a61d5efebfc3
+56SPo-L2nMN
diff --git a/public/structs b/public/structs
index 47089d0aa..78cc03f2b 100644
--- a/public/structs
+++ b/public/structs
@@ -46,7 +46,7 @@ records.
-
+
package main
|
@@ -88,8 +88,10 @@ records.
- 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.
|
|