Skip to content

Instantly share code, notes, and snippets.

@drashtivedgowitek
Created Aug 1, 2019
Embed
What would you like to do?
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