From 7cde0793f392e5cef17e4064675ed20d00d4ced2 Mon Sep 17 00:00:00 2001 From: Gentleelephant <1132960613@qq.com> Date: Thu, 25 Jul 2024 14:36:28 +0800 Subject: [PATCH] Fix memory issue in PriorityQueue Slice method --- flow/queue.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/flow/queue.go b/flow/queue.go index 9953d49..0bbc525 100644 --- a/flow/queue.go +++ b/flow/queue.go @@ -65,5 +65,11 @@ func (pq *PriorityQueue) Update(item *Item, newEpoch int64) { // Slice returns a sliced PriorityQueue using the given bounds. func (pq PriorityQueue) Slice(start, end int) PriorityQueue { - return pq[start:end] + // Create a new slice with the desired length + subQueue := make(PriorityQueue, end-start) + + // Copy the elements from the original slice to the new slice + copy(subQueue, pq[start:end]) + + return subQueue }