以下服务器代码:


package main


import (

  "fmt"

  "net/http"

)


func handler(w http.ResponseWriter, r *http.Request) {

  file, _, err := r.FormFile("file")

  if err != nil {

    fmt.Fprintln(w, err)

    return

  }

  defer file.Close()


  return

}


func main() {

  http.ListenAndServe(":8081", http.HandlerFunc(handler))

}

正在运行,然后使用以下命令调用它:


curl -i -F "file=@./large-file" --form hello=world http://localhost:8081/

在large-filedarwin/amd64 和 linux/amd64 上的 Go 1.4.2 中,大约 80MB 似乎存在某种形式的内存泄漏。


当我连接时pprof,我看到bytes.makeSlice在多次调用服务后使用了 96MB 的内存(最终r.FormFile在我上面的代码中调用)。


如果我继续调用curl,进程的内存使用会随着时间的推移而变慢,最终似乎在我的机器上停留在 300MB 左右。


想法?我认为这不是预期的/我做错了什么?