SetProcessWorkingSetSize reduces memory usage,
[DllImport ("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]
Public static extern int SetProcessWorkingSetSize (IntPtr process, int minSize, int maxSize );
/// <Summary>
/// Release the memory
/// </Summary>
Public static void ClearMemory ()
{
GC. Collect ();
GC. WaitForPendingFinalizers ();
If (Environment. OSVersion. Platform = PlatformID. Win32NT)
{
SetProcessWorkingSetSize (Process. GetCurrentProcess (). Handle,-1,-1 );
}
}
How to obtain the memory size occupied by the current application:
/// <Summary>
/// Release the memory
/// </Summary>
Public static void ClearMemory ()
{
// Obtain the current Working Process
Process proc = Process. GetCurrentProcess ();
Long usedMemory = proc. PrivateMemorySize64;
If (usedMemory> 1024*1024*20)
{
GC. Collect ();
GC. WaitForPendingFinalizers ();
If (Environment. OSVersion. Platform = PlatformID. Win32NT)
{
SetProcessWorkingSetSize (Process. GetCurrentProcess (). Handle,-1,-1 );
}
}
}