| The status of this resource is Pending. The webmaster may be reviewing this resource or have put on hold. |
//add these name space using System.Collections; using System.Runtime.InteropServices;
class Memory { [DllImport("kernel32.dll")] public static extern bool SetProcessWorkingSetSize( IntPtr proc, int min, int max ); public void ReduceMemory() { GC.Collect() ; GC.WaitForPendingFinalizers() ; if(Environment.OSVersion.Platform == PlatformID.Win32NT) { SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1) ; } public void Memory() { ReduceMemory() ; } }
Call ReduceMemory() method in form load or in constructor of the class
We can temporarily trim the working set of the specified process to zero by setting -1 for both dwMinimumWorkingSetSize and dwMaximumWorkingSetSize. But gradually application starts acquiring memory, so in the long run we can call SetProcessWorkingSetSize function for every 30 seconds using timer. This will make sure that our application use less memory.
|
No responses found. Be the first to respond and make money from revenue sharing program.
|