mirror of
https://github.com/golang/go
synced 2024-11-17 06:54:48 -07:00
Set element in slice to nil avoiding memory leak.
This commit is contained in:
parent
73b803ee53
commit
1bae5d3758
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user