Skip to content

Instantly share code, notes, and snippets.

@leosabbir
Created February 23, 2019 20:12
Show Gist options
  • Save leosabbir/b5b8288b635682f28a4ab392b29e8492 to your computer and use it in GitHub Desktop.
Save leosabbir/b5b8288b635682f28a4ab392b29e8492 to your computer and use it in GitHub Desktop.
Verifies that the varible accessed by defer method are evaluated only when the method is executed not at the time of defer execution.
package main
import (
"fmt"
)
type Data struct {
name string
}
func main() {
ss := &Data{"Giney"}
defer func () {
fmt.Println(ss.name)
}()
fmt.Println(ss.name)
ss = nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment