Skip to content

Commit

Permalink
trie: add finalizer to free memory from cleans fastcache
Browse files Browse the repository at this point in the history
  • Loading branch information
tsahee committed Oct 30, 2022
1 parent de0b8c2 commit 690db35
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions trie/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,17 @@ func NewDatabaseWithConfig(diskdb ethdb.KeyValueStore, config *Config) *Database
}},
preimages: preimage,
}
runtime.SetFinalizer(db, (*Database).finalizer)
return db
}

// must call Reset() to reclaim memory used by fastcache
func (db *Database) finalizer() {
if db.cleans != nil {
db.cleans.Reset()
}
}

// insert inserts a simplified trie node into the memory database.
// All nodes inserted by this function will be reference tracked
// and in theory should only used for **trie nodes** insertion.
Expand Down

0 comments on commit 690db35

Please sign in to comment.