/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> public void Dispose( ) { FinalPrivateBytes = Process.GetCurrentProcess( ).PrivateMemorySize64; string message = string.Empty; if (Arguments != null && Arguments.Length > 0) { message = string.Join(", ", Arguments.Select(arg => $"{arg.Key}: {arg.Value}")); message += ", "; } message += $"Initial Memory: {TenantHealthHelpers.ToPrettySize( InitialPrivateBytes, 2 )}, Final Memory: {TenantHealthHelpers.ToPrettySize( FinalPrivateBytes, 2 )}, Difference: {TenantHealthHelpers.ToPrettySize( FinalPrivateBytes - InitialPrivateBytes, 2 )}"; Trace.WriteLine(message); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose( ) { long completePrivateBytes = Process.GetCurrentProcess( ).PrivateMemorySize64; if (completePrivateBytes > Threshold) { Trace.WriteLine($"Private bytes exceeded {TenantHealthHelpers.ToPrettySize( Threshold, 2 )}. Running cleanup action..."); Action.Invoke( ); if (CollectGarbage) { GC.Collect( ); } } Action = null; }