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)

out

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)

Most upvoted comments

Ping

Yes, I can confirm the memory leak. It’s caused by some global variable references, but I do not know which global variable.