1
0
mirror of https://github.com/golang/go synced 2024-11-17 09:14:46 -07:00

Set element in slice to nil avoiding memory leak.

This commit is contained in:
WhisperRain 2019-02-25 16:24:02 +08:00
parent 73b803ee53
commit 1bae5d3758

View File

@ -45,6 +45,7 @@ func (pq *PriorityQueue) Pop() interface{} {
old := *pq
n := len(old)
item := old[n-1]
old[n-1] = nil // avoid memory leak
item.index = -1 // for safety
*pq = old[0 : n-1]
return item