未验证 提交 286da9e6 编写于 作者: M Michal Strehovský 提交者: GitHub

Change logic around GC.Collect in objwriter (#83249)

上级 7a0b0e13
......@@ -1149,15 +1149,16 @@ public static void EmitObject(string objectFilePath, IReadOnlyCollection<Depende
}
}
if (logger.IsVerbose)
logger.LogMessage($"Emitting debug information");
// Native side of the object writer is going to do more native memory allocations.
// Free up as much memory as possible so that we don't get OOM killed.
// This is potentially a waste of time. We're about to end the process and let the
// OS "garbage collect" the entire address space.
var gcMemoryInfo = GC.GetGCMemoryInfo();
if (gcMemoryInfo.TotalCommittedBytes > gcMemoryInfo.TotalAvailableMemoryBytes / 2)
var gcInfo = GC.GetGCMemoryInfo();
if (logger.IsVerbose)
logger.LogMessage($"Memory stats: {gcInfo.TotalCommittedBytes} bytes committed, {gcInfo.TotalAvailableMemoryBytes} bytes available");
if (gcInfo.TotalCommittedBytes > gcInfo.TotalAvailableMemoryBytes / 5)
{
if (logger.IsVerbose)
logger.LogMessage($"Freeing up memory");
......@@ -1165,6 +1166,9 @@ public static void EmitObject(string objectFilePath, IReadOnlyCollection<Depende
GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive);
}
if (logger.IsVerbose)
logger.LogMessage($"Emitting debug information");
objectWriter.EmitDebugModuleInfo();
succeeded = true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册