mirror of
https://github.com/golang/go
synced 2024-09-15 22:20:06 +00:00
container/heap: avoid memory leak in example
Set element in slice to nil avoiding memory leak.
Change-Id: I9dbef9a0466407011e326725d3a0b681cd815389
GitHub-Last-Rev: 1bae5d3758
GitHub-Pull-Request: golang/go#30386
Reviewed-on: https://go-review.googlesource.com/c/163601
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
e609bd373f
commit
7a9968f96f
|
@ -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 a new issue