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 considerably and is back up when the application is maximized.
I read somewhere that the .NET process reserves a lot of memory for runtime allocation in advance. That's why .NET applications have a larger memory footprint to start with. But this memory can be released using Win32 API calls. A trade-off is that runtime allocation becomes slow - is that true?
Usage of memory profiler to detect a memory leak DotMemory, SciTech Memory Profiler, and ANTS Memory Profiler are the most popular.NET memory profilers. If you have Visual Studio Enterprise, you may also use a "free" profiler. Memory profilers all work in the same way.
Memory footprint refers to the amount of main memory that a program uses or references while running. The word footprint generally refers to the extent of physical dimensions that an object occupies, giving a sense of its size.
Memory allocationGarbage Collector (GC) is the part of the . NET framework that allocates and releases memory for your . NET applications. When a new process is started, the runtime reserves a region of address space for the process called the managed heap.
Whereas disk footprint of an application refers to its storage size, runtime footprint translates to memory requirements at execution time.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With