rcrowley/go-metrics — pull request #45 by laurent-descrivan (2014-03-28 11:45:26+00:00)
Title: Allow lazy instantiation of metric in GetOrRegister.

This fixes also memleaks in GetOrRegister* due to this non-lazy instantiation.

Hi,

I am using your library for an http server that serves thousands of QPS. We came across a memleak: each time a GetOrRegister* is called, the metric is created, _then_ check against the registry, and dropped if the metric did indeed exist. This is instantiation is not efficient, but moreover it creates a goroutine that never ends each time, leading to a severe memleak.

Since we called GetOrRegister in each queries, I could have work around by not using GetOrRegister and keeping the same metric in a variable, but this patch takes care of the root cause of the problem.

Test case in included. Hope you will be able to merge, thanks.