I have a code that has this structure:
package main
import (
"html/template"
"net/http"
"log"
)
func main() {
http.HandleFunc("/",myFunction)
http.HandleFunc("/route2",mySecondFunction)
http.HandleFunc("/route3",myThirdFunction)
http.ListenAndServe(":8080",nil)
}
func check(err error){
if err != nil{
log.Fatal(err)
}
}
func myFunction(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 request.html
file and it runs in localhost: 8080
, see the routes I set in http.HandleFunc("/", myFunction)
.
I could see that in task manager, even when the server was idle, memory usage never decreased, only increasing according to the amount of calls I made to the server.
Init state:
After some requests:
And this working set never decreased
How can I do to free up the memory that has already been used and at the same time not disable the server?