空闲时释放服务器内存空间

时间:2017-03-26 16:08:22

标签: go

我有一个具有以下结构的代码:

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)
    }
}

此代码只是创建一个服务器,其中包含request.html文件中的任何内容,并且它在localhost: 8080中运行,请参阅我在http.HandleFunc("/", myFunction)中设置的路由。

我可以在任务管理器中看到,即使服务器处于空闲状态,内存使用率也不会下降,只会根据我对服务器的调用量而增加。

初始状态:

enter image description here

经过一些要求:

enter image description here

这个工作集从未减少

如何释放已经使用的内存,同时不禁用服务器?

0 个答案:

没有答案
相关问题