Skip to content

Conversation

jdamick
Copy link

@jdamick jdamick commented Jan 28, 2025

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

@jdamick
Copy link
Author

jdamick commented Jan 28, 2025

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

@jdamick
Copy link
Author

jdamick commented Feb 3, 2025

@chrisohaver / @miekg wdyt?

@jdamick
Copy link
Author

jdamick commented Feb 14, 2025

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

@jdamick
Copy link
Author

jdamick commented Sep 23, 2025

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

Copy link

@thevilledev thevilledev left a comment

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 <[email protected]>
@jdamick
Copy link
Author

jdamick commented Sep 25, 2025

@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

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