Description

PrepareStmt=true开启的时候内存泄露,如果有大批量数据的更新或者插入,内存会一直增长 生产环境开启之后,内存耗尽导致宕机2次

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: ivila

@hojit 根据你的描述,我觉得大概率并不是内存泄漏,而是内存增长问题。 使用PrepareStatement时,gorm会根据对应的SQL语句缓存statement,可以看这里:https://github.com/go-gorm/gorm/blob/4a50b36f638c6899089e6e3457425528ce693933/prepare_stmt.go#L20 所以会内存一直增长,你可以调整一下你的实例内存大小,或者针对你的大批量数据的更新或者插入场景单独使用其它的gorm实例。 或者如果你觉得可能真的有内存泄漏问题的话,那就开pprof,golang debug这些东西其实挺方便的。

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: xgzlucario

我们也有遇到过相同的问题,检查一下业务代码中 RAW SQL 的 pattern 是否都符合 "update xxx where time = ?" 的形式,而不是把具体的值直接写在了 pattern 里面

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking