Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1150,14 +1150,30 @@ public static void EmitObject(string objectFilePath, IReadOnlyCollection<Depende
}

if (logger.IsVerbose)
logger.LogMessage($"Finalizing output to '{objectFilePath}'...");
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)
{
if (logger.IsVerbose)
logger.LogMessage($"Freeing up memory");

GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive);
}

objectWriter.EmitDebugModuleInfo();

succeeded = true;
}
finally
{
if (logger.IsVerbose)
logger.LogMessage($"Finalizing output to '{objectFilePath}'...");

objectWriter.Dispose();

if (!succeeded)
Expand All @@ -1173,6 +1189,9 @@ public static void EmitObject(string objectFilePath, IReadOnlyCollection<Depende
}
}
}

if (logger.IsVerbose)
logger.LogMessage($"Done writing object file");
}

[DllImport(NativeObjectWriterFileName)]
Expand Down