I have a code more or less with this structure:
package main
import (
"html/template"
"net/http"
"log"
)
func main() {
http.HandleFunc("/",taltal)
http.ListenAndServe(":8080",nil)
}
func check(err error){
if err != nil{
log.Fatal(err)
}
}
func taltal(w http.ResponseWriter, r *http.Request){
if r.Method == "GET"{
t,err := template.ParseFiles("request.html")
check(err)
t.Execute(w,nil)
}
}
This code simply creates a server with whatever it has in the file request.html
and it runs in localhost:8080
, see the routes I set in http.HandleFunc("/",taltal)
.
I noticed that in the task manager, even when the server was idle, memory usage never decreased, it only increased according to the amount of calls I made to the server.
Initial status:
Aftermakingsomerequests:
And memory usage never slows, even when the server is idle.
How do I free the memory that is no longer being used and at the same time do not crash the server?