tidb: memory leak in mockstore
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
package main
import (
"os"
"runtime/pprof"
"github.com/pingcap/tidb/session"
. "github.com/pingcap/tidb/store/mockstore"
)
func testMock() {
opts := []MockTiKVStoreOption{WithStoreType(MockTiKV)}
store, _ := NewMockStore(opts...)
defer store.Close()
dom, _ := session.BootstrapSession(store)
defer dom.Close()
}
func main() {
for i := 0; i < 10; i++ {
testMock()
}
f, _ := os.Create("heap_profile")
pprof.WriteHeapProfile(f)
}
2. What did you expect to see? (Required)
free the memory when dom.Close()
3. What did you see instead (Required)
4. Affected version (Required)
tidb master
5. Root Cause Analysis
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 21 (16 by maintainers)
I found statisticsList will always hold the statistics which is probably a
*ddl.ddl
. https://github.com/pingcap/tidb/blob/c26038ba5eb32bc12689f00fb6c73763dfbc0339/sessionctx/variable/statusvar.go#L46-L50After clear domap and comment the follow two lines, the memory won’t increase all the time.
https://github.com/pingcap/tidb/blob/c26038ba5eb32bc12689f00fb6c73763dfbc0339/bindinfo/handle.go#L120 https://github.com/pingcap/tidb/blob/c26038ba5eb32bc12689f00fb6c73763dfbc0339/ddl/ddl.go#L386
Ping
Yes, I can confirm the memory leak. It’s caused by some global variable references, but I do not know which global variable.