-
-
Save drashtivedgowitek/9b578e4821df94c121ebf13d497aabae 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 ( | |
"fmt" | |
"log" | |
"net/http" | |
"net/http/pprof" | |
"sync" | |
"time" | |
"github.com/gorilla/mux" | |
) | |
func main() { | |
// we need a webserver to get the pprof webserver | |
go func() { | |
// Create a new router | |
router := mux.NewRouter() | |
// Register pprof handlers | |
router.Handle("/debug/pprof/heap", pprof.Handler("heap")) | |
log.Println(http.ListenAndServe("localhost:8080", router)) | |
}() | |
fmt.Println("hello world") | |
var wg sync.WaitGroup | |
wg.Add(1) | |
go leaks(wg) | |
wg.Wait() | |
} | |
func leaks(wg sync.WaitGroup) { | |
defer wg.Done() | |
s := make([]string, 3) | |
for i := 0; i < 10000000; i++ { | |
s = append(s, "I am leaking memory") | |
if (i % 100000) == 0 { | |
time.Sleep(500 * time.Millisecond) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment