Why is the memory block not cleared by the garbage collector?

package main

import (
        "fmt"
        "net/http"
        "runtime"
)

func handler(w http.ResponseWriter, r *http.Request) {
       largeMemAlloc := make([]int, 100000000)
       largeMemAlloc[1] = 100//lol
       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.

+3
source share
1 answer

Go , ​​ (GC). , . . , GC . API, JVM Linux. OOM - , Linux, GC , .

, , Go . Go 1.3 , , , 9 (GC, 2 + 7 , ).

, runtime.debug.FreeOSMemory(), , , , .

+1

Source: https://habr.com/ru/post/1609121/


All Articles