From 57ab3a1e9f66d0077bceb1f0745e383c57401667 Mon Sep 17 00:00:00 2001 From: Timur Mustafin Date: Fri, 19 Mar 2021 00:30:07 +0300 Subject: [PATCH] [crossgen2] Implement Dispose in Compilation. _corInfoImpls elements keeps _compilation reference which keeps reference to whole table _corInfoImpls. The circular referene together with issue #12255 potentionally leads to memory leak in crossgen2 if that table is created more than once. Dispose() method clears the table and prevents memory leak. Signed-off-by: Timur Mustafin --- .../Compiler/ReadyToRunCodegenCompilation.cs | 9 ++++++++- src/coreclr/tools/aot/crossgen2/Program.cs | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs index 99fda2800d5a15..0573222b6791be 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs @@ -23,7 +23,7 @@ namespace ILCompiler { - public abstract class Compilation : ICompilation + public abstract class Compilation : ICompilation, IDisposable { protected readonly DependencyAnalyzerBase _dependencyGraph; protected readonly NodeFactory _nodeFactory; @@ -67,6 +67,7 @@ protected Compilation( _methodILCache = new ILCache(ilProvider, NodeFactory.CompilationModuleGroup); } + public abstract void Dispose(); public abstract void Compile(string outputFileName); public abstract void WriteDependencyLog(string outputFileName); @@ -218,6 +219,7 @@ public interface ICompilation { void Compile(string outputFileName); void WriteDependencyLog(string outputFileName); + void Dispose(); } public sealed class ReadyToRunCodegenCompilation : Compilation @@ -638,5 +640,10 @@ protected override void ComputeDependencyNodeDependencies(List NodeFactory.CopiedFieldRva(field); + + public override void Dispose() + { + _corInfoImpls?.Clear(); + } } } diff --git a/src/coreclr/tools/aot/crossgen2/Program.cs b/src/coreclr/tools/aot/crossgen2/Program.cs index cd906d2799c1ef..d20c3a398cdce3 100644 --- a/src/coreclr/tools/aot/crossgen2/Program.cs +++ b/src/coreclr/tools/aot/crossgen2/Program.cs @@ -632,6 +632,7 @@ private int Run(string[] args) if (_commandLineOptions.DgmlLogFileName != null) compilation.WriteDependencyLog(_commandLineOptions.DgmlLogFileName); + compilation.Dispose(); } return 0;