Happens on MultiInstance counters.
We have roughly 20 clients connected at once, and have the server app track its own performance in serving each client.
As clients disconnect, we dispose of the CounterHelper for the instance. This doesn't seem to be enough, as after a while, we get an
InvalidOperationException: Custom counters file view is out of memory
Illustrated in the following test app:
static void Main(string args)
var i = 0;
var helper = PerformanceHelper.CreateCounterHelper<ClientPerformanceCounters>(i.ToString());
// runs out of memory after a few hundred instances were created and disposed.
[PerformanceCounterCategory("Client Counters", PerformanceCounterCategoryType.MultiInstance, "")]
public enum ClientPerformanceCounters
[PerformanceCounter("Scan Duration", "", PerformanceCounterType.NumberOfItems32)]
What exactly is the right way to dispose of individual instances?
We've tried to do helper.GetInstance(..).RemoveInstance() which works well, but if we add helper.Dispose() right after, we hit the same out of memory error.
Can we get away without calling helper.Dispose() ??