Skip to content

Commit 690db35

Browse files
committed
trie: add finalizer to free memory from cleans fastcache
1 parent de0b8c2 commit 690db35

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

trie/database.go

+8
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,17 @@ func NewDatabaseWithConfig(diskdb ethdb.KeyValueStore, config *Config) *Database
301301
}},
302302
preimages: preimage,
303303
}
304+
runtime.SetFinalizer(db, (*Database).finalizer)
304305
return db
305306
}
306307

308+
// must call Reset() to reclaim memory used by fastcache
309+
func (db *Database) finalizer() {
310+
if db.cleans != nil {
311+
db.cleans.Reset()
312+
}
313+
}
314+
307315
// insert inserts a simplified trie node into the memory database.
308316
// All nodes inserted by this function will be reference tracked
309317
// and in theory should only used for **trie nodes** insertion.

0 commit comments

Comments
 (0)