You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
The text was updated successfully, but these errors were encountered: