forked from cerc-io/plugeth
core/state, tests: fix memory leak via fastcache (#28387)
This change fixes a memory leak, when running either state-tests or blockchain-tests, we allocate a `1MB` fastcache during snapshot generation. `fastcache` is a bit special, and requires a `Reset()` (it has it's own memory allocator). The `1MB` was hidden [here](https://github.com/ethereum/go-ethereum/blob/master/tests/state_test_util.go#L333) and [here](https://github.com/ethereum/go-ethereum/blob/master/tests/block_test_util.go#L146) respectively.
This commit is contained in:
@@ -45,6 +45,16 @@ type diskLayer struct {
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
// Release releases underlying resources; specifically the fastcache requires
|
||||
// Reset() in order to not leak memory.
|
||||
// OBS: It does not invoke Close on the diskdb
|
||||
func (dl *diskLayer) Release() error {
|
||||
if dl.cache != nil {
|
||||
dl.cache.Reset()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Root returns root hash for which this snapshot was made.
|
||||
func (dl *diskLayer) Root() common.Hash {
|
||||
return dl.root
|
||||
|
||||
@@ -656,6 +656,13 @@ func diffToDisk(bottom *diffLayer) *diskLayer {
|
||||
return res
|
||||
}
|
||||
|
||||
// Release releases resources
|
||||
func (t *Tree) Release() {
|
||||
if dl := t.disklayer(); dl != nil {
|
||||
dl.Release()
|
||||
}
|
||||
}
|
||||
|
||||
// Journal commits an entire diff hierarchy to disk into a single journal entry.
|
||||
// This is meant to be used during shutdown to persist the snapshot without
|
||||
// flattening everything down (bad for reorgs).
|
||||
|
||||
Reference in New Issue
Block a user