From 78726da52c6abedc94e5c4345759028f239b2938 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Thu, 12 May 2022 19:24:24 +0200 Subject: [PATCH] Fix memory leak at AssemblyLoadContext unload I have found there was a small memory leak when unloading AssemblyLoadContext. A customer had a quite extreme testing case that ran millions of iterations of creating an AssemblyLoadContext, loading some assemblies into it and then unloading it. After 80 million iterations on their machine with 8GB memory, the testing app was getting out of memory. Using PerfView, I was able to locate the source of the leak. It was a missing destruction of the Module::m_pJitInlinerTrackingMap. --- src/coreclr/vm/ceeload.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index 0f4904d29bf10..86ff274d9d00d 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -1350,6 +1350,10 @@ void Module::Destruct() m_file->Release(); } +#if defined(PROFILING_SUPPORTED) + delete m_pJitInlinerTrackingMap; +#endif + // If this module was loaded as domain-specific, then // we must free its ModuleIndex so that it can be reused FreeModuleIndex();