.NET EXE memory footprint

前端 未结 3 837
不思量自难忘°
不思量自难忘° 2020-12-01 02:22

Even a simple Notepad application in C# consumes megabytes of RAM as seen in the task manager. On minimizing the application the memory size in the task manager goes down co

3条回答
  •  长情又很酷
    2020-12-01 02:54

    The reason for the large memory footprint is that the JIT compiler and Windows Forms engine are being loaded with your process. To reduce this, you can do the following:

    [DllImport("psapi.dll")]
    static extern int EmptyWorkingSet(IntPtr hwProc);
    
    static void MinimizeFootprint()
    {
        EmptyWorkingSet(Process.GetCurrentProcess().Handle);
    }
    

    This should remove as much as possible from your memory footprint. There may be a way that you can also reduce the amount of memory that is set aside for runtime memory allocation.

提交回复
热议问题