我有以下 http 处理程序的代码,它在随后的请求中从 Amazon S3 下载原始图像并将其转换为所需的纵横比并将其保存回 s3。这段代码会泄漏内存,一段时间后它会崩溃。我从我这边处理了所有事情,并对代码进行了分析。但是,还是想不通问题。如果有人能在这里弄清楚,将不胜感激。仅供参考,我正在使用该go version go1.5.3 linux/amd64版本。分析输出:3259.27kB of 3302.42kB total (98.69%)Dropped 258 nodes (cum <= 16.51kB)Showing top 30 nodes out of 91 (cum >= 27.76kB) flat flat% sum% cum cum% 1552.59kB 47.01% 47.01% 1552.59kB 47.01% bytes.makeSlice 584kB 17.68% 64.70% 584kB 17.68% imagick._Cfunc_GoBytes 257.38kB 7.79% 72.49% 257.38kB 7.79% encoding/pem.Decode 168.11kB 5.09% 77.58% 168.11kB 5.09% crypto/tls.(*block).reserve 165.09kB 5.00% 82.58% 389.49kB 11.79% crypto/x509.parseCertificate 105.32kB 3.19% 85.77% 105.32kB 3.19% reflect.unsafe_NewArray 83.64kB 2.53% 88.30% 83.64kB 2.53% math/big.nat.make 75.55kB 2.29% 90.59% 75.55kB 2.29% net/http.(*Transport).dialConn 64.02kB 1.94% 92.53% 64.02kB 1.94% regexp.(*bitState).reset 43.77kB 1.33% 93.85% 43.77kB 1.33% crypto/x509.(*CertPool).AddCert 40.44kB 1.22% 95.08% 40.44kB 1.22% crypto/x509/pkix.(*Name).FillFromRDNSequence 40.16kB 1.22% 96.29% 40.16kB 1.22% encoding/asn1.parsePrintableString 24.07kB 0.73% 97.02% 24.07kB 0.73% net/http.newBufioWriterSize 18.98kB 0.57% 97.60% 18.98kB 0.57% net/http.newBufioReader 16.14kB 0.49% 98.09% 64.77kB 1.96% crypto/tls.(*Conn).readHandshake 12.01kB 0.36% 98.45% 237.09kB 7.18% encoding/asn1.parseField 8.01kB 0.24% 98.69% 91.65kB 2.78% crypto/x509.parsePublicKey 0 0% 98.69% 112.33kB 3.40% bufio.(*Reader).Read 0 0% 98.69% 80.32kB 2.43% bufio.(*Reader).fill 0 0% 98.69% 27.76kB 0.84% bufio.(*Writer).ReadFrom 0 0% 98.69% 27.76kB 0.84% bufio.(*Writer).flush 0 0% 98.69% 1648.33kB 49.91% bytes.(*Buffer).ReadFrom
1 回答
墨色风雨
TA贡献1853条经验 获得超6个赞
你正在泄漏一根魔杖。
在这里,您分配一个新魔杖并将其推迟销毁:
tx := imagick.NewMagickWand() defer tx.Destroy()
但是再往下,在“if”块中,您将其替换为从调用返回的魔杖TransformImage()
:
tx = mw.TransformImage("", size) tx.SetImageGravity(imagick.GRAVITY_CENTER)
如果您完全摆脱了新魔杖的第一次分配,只需确保Destroy()
从 返回的新魔杖TransformImage()
,泄漏就会消失。
Ref上的问题跟踪,#72,详情
- 1 回答
- 0 关注
- 145 浏览
添加回答
举报
0/150
提交
取消