Browse Source

store: optimize ttlKeyHeap GC

It helps to recycle nodes in heap array, whose value can be unlimited
long.
Yicheng Qin 11 years ago
parent
commit
c104ca89c2
1 changed files with 4 additions and 0 deletions
  1. 4 0
      store/ttl_key_heap.go

+ 4 - 0
store/ttl_key_heap.go

@@ -59,6 +59,10 @@ func (h *ttlKeyHeap) Pop() interface{} {
 	old := h.array
 	old := h.array
 	n := len(old)
 	n := len(old)
 	x := old[n-1]
 	x := old[n-1]
+	// Set slice element to nil, so GC can recycle the node.
+	// This is due to golang GC doesn't support partial recycling:
+	// https://github.com/golang/go/issues/9618
+	old[n-1] = nil
 	h.array = old[0 : n-1]
 	h.array = old[0 : n-1]
 	delete(h.keyMap, x)
 	delete(h.keyMap, x)
 	return x
 	return x