Skip to content

Instantly share code, notes, and snippets.

@yumed15
Last active November 21, 2023 15:35
Show Gist options
  • Save yumed15/de7ccb23bbbe6d42474f0fe04e9e4212 to your computer and use it in GitHub Desktop.
Save yumed15/de7ccb23bbbe6d42474f0fe04e9e4212 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/pkg/profile"
)
type UserData struct {
ID int
Name string
}
func createObject() *UserData {
user := UserData{ID: 1, Name: "John Doe"}
return &user // Returning a pointer to the local variable
}
func main() {
defer profile.Start(profile.TraceProfile, profile.ProfilePath(".")).Stop()
var user *UserData
for i := 0; i < 1000000; i++ {
// Creating objects inside a loop
user = createObject()
_ = user // Ignoring the variable to simulate escape
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment