[ACCEPTED]-.NET EXE memory footprint-.net
The reason for the large memory footprint 7 is that the JIT compiler and Windows Forms engine are 6 being loaded with your process. To reduce 5 this, you can do the following:
[DllImport("psapi.dll")]
static extern int EmptyWorkingSet(IntPtr hwProc);
static void MinimizeFootprint()
{
EmptyWorkingSet(Process.GetCurrentProcess().Handle);
}
This should 4 remove as much as possible from your memory 3 footprint. There may be a way that you can 2 also reduce the amount of memory that is 1 set aside for runtime memory allocation.
TaskManager should not be used to measure 21 the memory footprint of a .NET application.
When 20 a .NET application starts, it asks the OS 19 for a chunk of memory which it then segments 18 to become the managed heap, stack, and large 17 object heap. It is this total chunk of memory 16 that TaskManager is reporting, which may 15 or may not be completely used by .NET. Once 14 a .NET application is given a chunk of memory, it 13 will not release it until asked by the OS, which 12 will only happen with the OS determines 11 a need for more memory resources.
If you 10 want to measure memory allocations, you 9 need to look at the various performance 8 monitor (PerfMon) counters.
You can use interop 7 code to call Win32 APIs to trim your working 6 set size, but the next time your application 5 requests memory from the OS the working 4 set will go back up and there will be a 3 performance hit while the OS allocates and 2 hands out the additional memory and the 1 .NET runtime "configures" it.
The task manager does not show real life 7 usage of memory for a .NET app. To see that 6 you almost have to put a performance counter 5 on the app or use a profiler.
What you see 4 in the Task Manager is the working memory 3 of an app which includes a bunch of overhead 2 for the framework itself which must also 1 load when your app loads.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.