Browse Source

Add Release & Error methods to Iterator

We need this to properly support LevelDB backend, which needs
to be released if we don't want to leak memory.
pull/1842/head
Alexis Sellier 7 years ago
parent
commit
296d223545
2 changed files with 14 additions and 1 deletions
  1. +4
    -1
      db/db.go
  2. +10
    -0
      db/mem_db.go

+ 4
- 1
db/db.go View File

@ -10,10 +10,10 @@ type DB interface {
DeleteSync([]byte)
Close()
NewBatch() Batch
Iterator() Iterator
// For debugging
Print()
Iterator() Iterator
Stats() map[string]string
}
@ -28,6 +28,9 @@ type Iterator interface {
Key() []byte
Value() []byte
Release()
Error() error
}
//-----------------------------------------------------------------------------


+ 10
- 0
db/mem_db.go View File

@ -97,6 +97,16 @@ func (it *memDBIterator) Value() []byte {
return it.db.Get(it.Key())
}
func (it *memDBIterator) Release() {
it.db = nil
it.keys = nil
return
}
func (it *memDBIterator) Error() error {
return nil
}
func (db *MemDB) Iterator() Iterator {
it := newMemDBIterator()
it.db = db


Loading…
Cancel
Save