package main
import (
"fmt"
"net/http"
"runtime"
)
func handler(w http.ResponseWriter, r *http.Request) {
largeMemAlloc := make([]int, 100000000)
largeMemAlloc[1] = 100
fmt.Fprintf(w, "hi from handler")
runtime.GC()
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":7777", nil)
}
As soon as I find http://127.0.0.1:7777 4-5 times, the used memory goes to GB.
It was about 4-5 minutes, and the memory is still unclaimed by the OS. Why is this happening?
What am I doing wrong?
I compile it in go 1.5
Edit: after 10 minutes, memory usage was reduced to 50 MB. But I do not understand why so much time is required to restore this memory block. I feel like I'm doing something terribly wrong.
source
share