I've got a sample golang script: it gets page response and unmarshalles its body in infinitive loop as a goroutine.
package main
import (
"time"
"net/http"
"encoding/json"
"fmt"
_ "net/http/pprof"
)
func init() {
go http.ListenAndServe(":8087", http.DefaultServeMux)
}
func DoTask() {
resp, _ := http.Get("https://www.citibikenyc.com/stations/json")
defer resp.Body.Close()
var answerInterface map[string]interface{}
json.NewDecoder(resp.Body).Decode(&answerInterface)
}
func main() {
for {
go func() {
time.Sleep(1*time.Second)
DoTask()
fmt.Println("goroutine finished")
}()
time.Sleep(1*time.Second)
}
}
But when I open profiler the number of heap items is increasing all the time. Example of heap item:
# 0x6b7699 compress/flate.NewReader+0x49 /usr/local/go/src/compress/flate/inflate.go:828
# 0x5f339d compress/gzip.(*Reader).readHeader+0x7ad /usr/local/go/src/compress/gzip/gunzip.go:254
# 0x5f1da7 compress/gzip.NewReader+0x207 /usr/local/go/src/compress/gzip/gunzip.go:95
# 0x4d5117 net/http.(*gzipReader).Read+0x97 /usr/local/go/src/net/http/transport.go:1658
# 0x4d4c6a net/http.(*bodyEOFSignal).Read+0x26a /usr/local/go/src/net/http/transport.go:1613
# 0x502617 encoding/json.(*Decoder).refill+0x287 /usr/local/go/src/encoding/json/stream.go:152
# 0x5022a3 encoding/json.(*Decoder).readValue+0x413 /usr/local/go/src/encoding/json/stream.go:128
# 0x501ba9 encoding/json.(*Decoder).Decode+0x159 /usr/local/go/src/encoding/json/stream.go:57
# 0x401219 main.DoTask+0x169 /root/test.go:21
# 0x4012f9 main.main.func1+0x29 /root/test.go:30
Couldn't you explain, what is the problem? Thank you anyway