mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-18 04:54:54 +00:00
scheduler: Fix memory leak in scheduler cache
The `removeSlice` function was leaving behind references to the removed element, preventing it from being garbage-collected. This commit ensures that removed entries are fully cleared, eliminating the memory leak. Co-authored-by: ravisastryk <ravisastryk@gmail.com> Signed-off-by: Sujal Shah <sujalshah28092004@gmail.com>
This commit is contained in:
committed by
Sujal Shah
parent
54900791c4
commit
9dc5683c56
@@ -235,9 +235,11 @@ func (pl *DefaultPreemption) SelectVictimsOnNode(
|
||||
for _, pi := range nodeInfo.GetPods() {
|
||||
if pl.isPreemptionAllowed(nodeInfo, pi, pod) {
|
||||
potentialVictims = append(potentialVictims, pi)
|
||||
if err := removePod(pi); err != nil {
|
||||
return nil, 0, fwk.AsStatus(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, pi := range potentialVictims {
|
||||
if err := removePod(pi); err != nil {
|
||||
return nil, 0, fwk.AsStatus(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -386,6 +386,8 @@ func removeFromSlice(logger klog.Logger, s []fwk.PodInfo, k string) ([]fwk.PodIn
|
||||
removedPod = s[i]
|
||||
// delete the element
|
||||
s[i] = s[len(s)-1]
|
||||
// clear the reference to prevent potential memory leak
|
||||
s[len(s)-1] = nil
|
||||
s = s[:len(s)-1]
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user