fix: release memory after pop from heap (#42482)

issue: #42481

Signed-off-by: chyezh <chyezh@outlook.com>
This commit is contained in:
Zhen Ye 2025-06-04 10:00:32 +08:00 committed by GitHub
parent 490827974d
commit fc010e44a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 9 additions and 1 deletions

View File

@ -121,6 +121,7 @@ func (h *pendingBroadcastTaskArray) Pop() interface{} {
old := *h
n := len(old)
x := old[n-1]
old[n-1] = nil // release the memory of underlying array.
*h = old[0 : n-1]
return x
}

View File

@ -221,7 +221,7 @@ func (impl *flusherComponents) buildDataSyncServiceWithRetry(ctx context.Context
logger.Warn("fail to append flush message for segments that not created by streaming service into wal", zap.Error(err))
return err
}
impl.logger.Info("append flush message for segments that not created by streaming service into wal", zap.Stringer("msgID", appendResult.MessageID), zap.Uint64("timeTick", appendResult.TimeTick))
logger.Info("append flush message for segments that not created by streaming service into wal", zap.Stringer("msgID", appendResult.MessageID), zap.Uint64("timeTick", appendResult.TimeTick))
return nil
}, retry.AttemptAlways()); err != nil {
return nil, err

View File

@ -86,6 +86,7 @@ func (h *ackers) Pop() interface{} {
old := *h
n := len(old)
x := old[n-1]
old[n-1] = nil // release the memory of underlying array.
*h = old[0 : n-1]
return x
}

View File

@ -79,6 +79,7 @@ func (h *uncommittedTxnInfoOrderByMessageID) Pop() interface{} {
old := *h
n := len(old)
x := old[n-1]
old[n-1] = nil // release the memory of underlying array.
*h = old[0 : n-1]
return x
}

View File

@ -35,6 +35,7 @@ func (h *immutableMessageHeap) Pop() interface{} {
old := *h
n := len(old)
x := old[n-1]
old[n-1] = nil // release the memory of underlying array.
*h = old[0 : n-1]
return x
}

View File

@ -60,6 +60,8 @@ func (h *heapArray[E]) Pop() interface{} {
old := *h
n := len(old)
x := old[n-1]
var zero E
old[n-1] = zero // release the memory of underlying array.
*h = old[0 : n-1]
return x
}
@ -94,6 +96,8 @@ func (h *objectHeapArray[O, E]) Pop() interface{} {
old := h.objects
n := len(old)
x := old[n-1]
var zero O
old[n-1] = zero // release the memory of underlying array.
h.objects = old[0 : n-1]
return x
}