Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up IRuntime instance flushing #3895

Merged
merged 4 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation
public class Runtime : IRuntime, IDisposable
{
private readonly ClrInfo _clrInfo;
private readonly IDisposable _onFlushEvent;
private readonly ISymbolService _symbolService;
private Version _runtimeVersion;
private string _dacFilePath;
Expand Down Expand Up @@ -52,24 +51,19 @@ public Runtime(IServiceProvider services, int id, ClrInfo clrInfo)
_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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public RuntimeProvider(IServiceProvider services)
/// <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
Expand Down