Skip to content

Commit 57ab3a1

Browse files
committed
[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 <[email protected]>
1 parent ac5c33d commit 57ab3a1

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
namespace ILCompiler
2525
{
26-
public abstract class Compilation : ICompilation
26+
public abstract class Compilation : ICompilation, IDisposable
2727
{
2828
protected readonly DependencyAnalyzerBase<NodeFactory> _dependencyGraph;
2929
protected readonly NodeFactory _nodeFactory;
@@ -67,6 +67,7 @@ protected Compilation(
6767
_methodILCache = new ILCache(ilProvider, NodeFactory.CompilationModuleGroup);
6868
}
6969

70+
public abstract void Dispose();
7071
public abstract void Compile(string outputFileName);
7172
public abstract void WriteDependencyLog(string outputFileName);
7273

@@ -218,6 +219,7 @@ public interface ICompilation
218219
{
219220
void Compile(string outputFileName);
220221
void WriteDependencyLog(string outputFileName);
222+
void Dispose();
221223
}
222224

223225
public sealed class ReadyToRunCodegenCompilation : Compilation
@@ -638,5 +640,10 @@ protected override void ComputeDependencyNodeDependencies(List<DependencyNodeCor
638640
}
639641

640642
public ISymbolNode GetFieldRvaData(FieldDesc field) => NodeFactory.CopiedFieldRva(field);
643+
644+
public override void Dispose()
645+
{
646+
_corInfoImpls?.Clear();
647+
}
641648
}
642649
}

src/coreclr/tools/aot/crossgen2/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ private int Run(string[] args)
632632

633633
if (_commandLineOptions.DgmlLogFileName != null)
634634
compilation.WriteDependencyLog(_commandLineOptions.DgmlLogFileName);
635+
compilation.Dispose();
635636
}
636637

637638
return 0;

0 commit comments

Comments
 (0)