Skip to content

Instantly share code, notes, and snippets.

@drashtivedgowitek
Created August 1, 2019 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drashtivedgowitek/9b578e4821df94c121ebf13d497aabae to your computer and use it in GitHub Desktop.
Save drashtivedgowitek/9b578e4821df94c121ebf13d497aabae to your computer and use it in GitHub Desktop.
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