-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Description
Similar to #114599. When creating a Meter, it's added to a static List<Meter> and disposing it will remove it from the list, but when Dispose is never called, the Meter will stay in the list forever and never be collected.
runtime/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/Meter.cs
Lines 96 to 99 in e220a94
| lock (Instrument.SyncObject) | |
| { | |
| s_allMeters.Add(this); | |
| } |
runtime/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/Meter.cs
Lines 504 to 515 in e220a94
| lock (Instrument.SyncObject) | |
| { | |
| if (Disposed) | |
| { | |
| return; | |
| } | |
| Disposed = true; | |
| s_allMeters.Remove(this); | |
| instruments = _instruments; | |
| _instruments = new List<Instrument>(); | |
| } |
Reproduction:
using System.Diagnostics.Metrics;
for (int i = 0;; i++)
{
Meter m = new("");
if (i % 1_000_000 == 0)
{
Console.WriteLine(Environment.WorkingSet.ToString("N0"));
}
}