Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

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

Description

@AdamSLevy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions