使用以下代码将字节 [] 转换为字符串时,我发现奇怪的占用堆
package main
import (
"bytes"
"fmt"
"net/http"
_ "net/http/pprof"
"strings"
"time"
)
var (
c = make(chan int, 500000)
)
func main() {
go func() {
http.ListenAndServe(":8080", nil)
}()
f := func(ss []string) {
fmt.Println(ss)
time.Sleep(time.Millisecond)
<-c
}
for {
c <- 1
bs := bytes.NewBufferString("A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z").Bytes()
fmt.Println(bs) // will raise memory leak after marked as comment???
s := string(bs)
ss := strings.Split(s, ",")
go f(ss)
}
}
没有
fmt.Println(bs)
会逐渐耗尽记忆。工作
fmt.Println(bs)
正常。我不明白发生了什么?我和我一起工作version go1.9.2 darwin/amd64