yanyiwu / gojieba

"结巴"中文分词的Golang版本
MIT License
2.39k stars 302 forks source link

内存泄漏问题 #112

Open liu86th opened 8 months ago

liu86th commented 8 months ago

1 运行一段时间自动崩了,去掉x.Free() 这个就不会崩,但是内存占用好大啊,部署到k8s中去的时候 bug

CNLHC commented 5 months ago

I guess that the problem here is that you are trying to invoke x.Free() manually.

Actually, I add this line in order to make the golang GC to manage the underlying jieba memory which i consider the right way to write go program. https://github.com/yanyiwu/gojieba/pull/96

A quick fix is removing your manual invokation to the Free method and let the FInalizer do the free job.

My personal opinion is that the Free method should be private here. Because if gojieba keeps the Free method and rely on the user to manage the jieba memory, all the go objects that contain (directly or indirectly) the jieba instance will rely on the user to manage memory, which is not an ideal go pattern.