Skip to content

Force early cleanup of an instance when the instance list is re-sliced#7

Open
jdamick wants to merge 1 commit into
coredns:masterfrom
jdamick:master
Open

Force early cleanup of an instance when the instance list is re-sliced#7
jdamick wants to merge 1 commit into
coredns:masterfrom
jdamick:master

Conversation

@jdamick

@jdamick jdamick commented Jan 28, 2025

Copy link
Copy Markdown

On Stop() & Restart() to prevent holding memory for a potentially long time, nil out the instance before re-slicing to force early cleanup.

@jdamick

jdamick commented Jan 28, 2025

Copy link
Copy Markdown
Author

The other option would be to switch to slices.Delete(instances, i, i+1) since that will clear the removed elements.

@jdamick

jdamick commented Feb 3, 2025

Copy link
Copy Markdown
Author

@chrisohaver / @miekg wdyt?

@jdamick

jdamick commented Feb 14, 2025

Copy link
Copy Markdown
Author

been a couple weeks, trying someone else.. @johnbelamaric wdyt?

@jdamick

jdamick commented Sep 23, 2025

Copy link
Copy Markdown
Author

@thevilledev can u merge? this prevents memory leakage ..

@thevilledev thevilledev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jdamick - I don't have merge permissions to the repo, but I can help with the review. I would prefer slices.Delete as it makes the intent obvious. Other than that, LGTM.

@jdamick jdamick force-pushed the master branch 2 times, most recently from 76ef215 to ed369b5 Compare September 25, 2025 17:55
…d on Stop() & Restart() to prevent holding memory

Signed-off-by: Jeffrey Damick <jdamick@amazon.com>
@jdamick

jdamick commented Sep 25, 2025

Copy link
Copy Markdown
Author

@thevilledev i looked into replacing with slice but it would require changing the go.mod to bring the language support up to 1.18 for slices support. So I've left it as-is.

@thevilledev

Copy link
Copy Markdown

Yup, just realised it as well.

I did some further debugging through a memtest. This runs 10k restarts and GC + heap profile afterwards:

go test -run TestRestartDoesNotLeakInstances -v
go tool pprof -http=:8888 restart_heap.pb.gz
# or a diff of two runs
go tool pprof -top -diff_base=base.pb.gz new.pb.gz

Heap size and object counts remain stable before and after the proposed change. With the append-reslice a pointer is removed and len shortened.

@jdamick are you able to share more details about your issue, and possibly how that could be reproduced?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants