Skip to content

Commit

Permalink
[crossgen2] Fix memory leak in _corInfoImpls. (#49764)
Browse files Browse the repository at this point in the history
* [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 <t.mustafin@partner.samsung.com>

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

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
  • Loading branch information
t-mustafin and jkotas authored Mar 19, 2021
1 parent 89eece2 commit fc80be1
Show file tree
Hide file tree
Showing 2 changed files with 10 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();
}
}
}
2 changes: 2 additions & 0 deletions src/coreclr/tools/aot/crossgen2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,8 @@ private int Run(string[] args)

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

compilation.Dispose();
}

return 0;
Expand Down

0 comments on commit fc80be1

Please sign in to comment.