Skip to content

Commit

Permalink
[crossgen2] Implement Dispose in Compilation.
Browse files Browse the repository at this point in the history
_corInfoImpls elements keeps _compilation reference which keeps reference to whole table _corInfoImpls. The circular referene together with issue dotnet#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]>
  • Loading branch information
t-mustafin committed Mar 18, 2021
1 parent ac5c33d commit 57ab3a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace ILCompiler
{
public abstract class Compilation : ICompilation
public abstract class Compilation : ICompilation, IDisposable
{
protected readonly DependencyAnalyzerBase<NodeFactory> _dependencyGraph;
protected readonly NodeFactory _nodeFactory;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -218,6 +219,7 @@ public interface ICompilation
{
void Compile(string outputFileName);
void WriteDependencyLog(string outputFileName);
void Dispose();
}

public sealed class ReadyToRunCodegenCompilation : Compilation
Expand Down Expand Up @@ -638,5 +640,10 @@ protected override void ComputeDependencyNodeDependencies(List<DependencyNodeCor
}

public ISymbolNode GetFieldRvaData(FieldDesc field) => NodeFactory.CopiedFieldRva(field);

public override void Dispose()
{
_corInfoImpls?.Clear();
}
}
}
1 change: 1 addition & 0 deletions src/coreclr/tools/aot/crossgen2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ private int Run(string[] args)

if (_commandLineOptions.DgmlLogFileName != null)
compilation.WriteDependencyLog(_commandLineOptions.DgmlLogFileName);
compilation.Dispose();
}

return 0;
Expand Down

0 comments on commit 57ab3a1

Please sign in to comment.