Closed avriltank closed 2 years ago
[DllImport("psapi.dll")]
private static extern int EmptyWorkingSet(int hProcess);
public void GCFree()
{
GC.Collect();
GC.WaitForPendingFinalizers();
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
try
{
EmptyWorkingSet(System.Diagnostics.Process.GetCurrentProcess()
.Handle.ToInt32());
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
We can free memory by ourself,the raw gc behavior only frees the 2rd and 3rd resource when the memory size becomes the .net setted size.(this is the offical url:https://docs.microsoft.com/en-us/dotnet/core/runtime-config/garbage-collector)
I have try to change gc mod,there is no effect.
The .net Gc mod is very magic,same php code only takes 50m memory size,.net code takes 200m memory size.