Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use runtime.SetFinalizer on registration to avoid the need to Unregister meters or timers #280

Open
AdamSLevy opened this issue Dec 8, 2020 · 0 comments

Comments

@AdamSLevy
Copy link

Requiring users to Unregister metrics that they allow to be garbage collected is error prone and can then lead to GC leaks. However it is possible to leverage the garbage collector to perform final cleanup steps on an object. I propose that upon registration, a metric, counter, timer or gauge has an appropriate finalizer function set on it so that any cleanup operations can be performed.

This will likely require an additional nested layer of indirection so that the actual data that is saved in the registry does not prevent garbage collection on the outer object passed back to the user.

See https://golang.org/pkg/runtime/#SetFinalizer

I can come back with an example in code this weekend if this isn't clear enough.

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

No branches or pull requests

1 participant