IIS Memory Usage

305 views Asked by At

I start MVC app hosted in IIS. Open Task Manager and see that process uses about 55 MB. If to check the memory usage in one of the .net profiler it shows that

Total sizes of objects : 1.93MB
Memory allocated for .NET app: 17.46
Private Bytes : 57MB

What do this values mean? Why app that uses 1.93MB objects allocate about 55 MB RAM?

Some screenshots: https://i.stack.imgur.com/Gr0J2.png https://i.stack.imgur.com/Gr0J2.png

2

There are 2 answers

0
Brian Rasmussen On

Private bytes are pages allocated by the process. This is typically used to store data.

The CLR allocates memory on behalf of your managed application. This is reflected in private bytes. This memory - the managed heap - is allocated in chunks. The managed application creates objects that are stored on the managed heap. In addition to the managed heap the CLR allocates memory that it uses internally. This also adds to private bytes.

The total size of the objects is the sum of the size of the currently allocated objects. This number will always be smaller than private bytes.

0
simon at rcl On

Memory in Windows is quite a complicated thing: there are many different measurements. Have a look here (about halfway down) for a start.

However, you could guess that the 57MB of Private Bytes the profiler uses is the same as the 55MB that Task Manager uses. Do a search for Windows Memory Private Bytes (I think it's the same as Private Working Set in the page I linked to).

I don't know of any simple summary of how memory is organised. However, there is more loaded into memory than just the simple objects you are using. There is your code (has to be loaded or can't run), there is the .NET runtime, there are Stacks to keep track of where in the code you are and where to return when the current method finishes, and so on and so forth. Some memory can be shared between different processes if it's not going to be changed: the .NET runtime, your own code (probably). Some won't be shared: your data, your stacks.

Allocating memory is not just a case of "Oh, you need to store a string of 50 bytes - here you are!". Allocating 50 bytes at a time gets inefficient. Your program will grab a heap of memory at the start (it's actually called a heap), and gradually use it up. When its all used, it will grab a heap more. I'm not sure what the .NET runtime takes as a default - probably 64K at minimum but may well be more. As I say, it's complicated.