@@ -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
|
||||
|
@@ -1,2 +1,2 @@
|
||||
80344041b9268370bb6c73190afb1269e26f52fe
|
||||
ex1J3oieEeo
|
||||
b50c1756bf9a2ea7f8853f7f7cb7a61d5efebfc3
|
||||
56SPo-L2nMN
|
||||
|
8
public/structs
generated
8
public/structs
generated
@@ -46,7 +46,7 @@ records.</p>
|
||||
|
||||
</td>
|
||||
<td class="code leading">
|
||||
<a href="https://go.dev/play/p/ex1J3oieEeo"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
|
||||
<a href="https://go.dev/play/p/56SPo-L2nMN"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
|
||||
<pre class="chroma"><code><span class="line"><span class="cl"><span class="kn">package</span> <span class="nx">main</span></span></span></code></pre>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -88,8 +88,10 @@ records.</p>
|
||||
|
||||
<tr>
|
||||
<td class="docs">
|
||||
<p>You can safely return a pointer to local variable
|
||||
as a local variable will survive the scope of the function.</p>
|
||||
<p>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>
|
||||
|
||||
</td>
|
||||
<td class="code leading">
|
||||
|
Reference in New Issue
Block a user