Skip to content

Commit

Permalink
Fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Madeline Cameron committed Mar 18, 2017
1 parent 90811ea commit 1810fdc
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions forest.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ type treeNode struct {
children map[int]*treeNode
}

func (node *treeNode) recursiveDelete() {
for _, child := range node.children {
if len((child).children) > 0 {
(child).recursiveDelete()
}

if len(child.indices) > 0 {
node.indices = nil
}
}

node.indices = nil
node.children = nil
}

// recursiveAdd recurses down the tree to find the correct location to insert id.
// Returns whether a new hash value was added.
func (node *treeNode) recursiveAdd(level int, id int, tableKey hashTableKey) bool {
Expand Down Expand Up @@ -136,6 +151,12 @@ func NewLshForest(dim, l, m int, w float64) *LshForest {
}
}

func (index *LshForest) Delete() {
for _, tree := range index.trees {
(*tree.root).recursiveDelete()
}
}

// Insert adds a new data point to the LSH Forest.
// id is the unique identifier for the data point.
func (index *LshForest) Insert(point Point, id int) {
Expand Down

0 comments on commit 1810fdc

Please sign in to comment.