Are you using your own performance counters? We had the same exception in one of our applications, which created performance counters, but didn't dispose them properly.
Be aware that calling PerformanceCounter.Dispose()
is not enough - it just inherits from Component.Dispose()
and adds no additional functionality.
So always call PerformanceCounter.RemoveInstance()
when disposing an instance of a multi-instance PerformanceCounter, otherwise your PerformanceCounter instances will grow until the reserved memory (512 KB by default) is full.
A sample pattern looks so (this.performanceCounters is a dictionary with the used performance counters):
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (this.performanceCounters != null)
{
foreach (PerformanceCounter counter in this.performanceCounters.Values)
{
counter.RemoveInstance();
counter.Dispose();
}
this.performanceCounters = null;
}
}
}