Last active
November 21, 2023 15:35
-
-
Save yumed15/de7ccb23bbbe6d42474f0fe04e9e4212 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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