public class Runtime : IRuntime, IDisposable
{
private readonly ClrInfo _clrInfo;
- private readonly IDisposable _onFlushEvent;
private readonly ISymbolService _symbolService;
private Version _runtimeVersion;
private string _dacFilePath;
_serviceContainer.AddService<IRuntime>(this);
_serviceContainer.AddService(clrInfo);
- _onFlushEvent = Target.OnFlushEvent.Register(Flush);
-
Trace.TraceInformation($"Created runtime #{id} {clrInfo.Flavor} {clrInfo}");
}
void IDisposable.Dispose()
- {
- _serviceContainer.RemoveService(typeof(IRuntime));
- _serviceContainer.DisposeServices();
- _onFlushEvent.Dispose();
- }
-
- private void Flush()
{
if (_serviceContainer.TryGetCachedService(typeof(ClrRuntime), out object service))
{
- ((ClrRuntime)service).FlushCachedData();
+ // The DataTarget created in the RuntimeProvider is disposed here. The ClrRuntime
+ // instance is disposed below in DisposeServices().
+ ((ClrRuntime)service).DataTarget.Dispose();
}
+ _serviceContainer.RemoveService(typeof(IRuntime));
+ _serviceContainer.DisposeServices();
}
#region IRuntime
/// <param name="startingRuntimeId">The starting runtime id for this provider</param>
public IEnumerable<IRuntime> EnumerateRuntimes(int startingRuntimeId)
{
+ // The ClrInfo and DataTarget instances are disposed when Runtime instance is disposed. Runtime instances are
+ // not flushed when the Target/RuntimeService is flushed; they are all disposed and the list cleared. They are
+ // all re-created the next time the IRuntime or ClrRuntime instance is queried.
DataTarget dataTarget = new(new CustomDataTarget(_services.GetService<IDataReader>()))
{
FileLocator = null