Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET EXE memory footprint

Tags:

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?

like image 486
dotnetcoder Avatar asked Oct 21 '08 20:10

dotnetcoder


People also ask

How detect memory leak in .NET application?

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.

What is application memory footprint?

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.

How does .NET manage memory?

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.

What is runtime footprint?

Whereas disk footprint of an application refers to its storage size, runtime footprint translates to memory requirements at execution time.


1 Answers

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.

like image 76
Ed Altorfer Avatar answered Sep 21 '22 04:09

Ed Altorfer