Number of random RAM

I was hoping someone could explain why my application uses a different amount of RAM when loading. I'm talking about the compiled version that uses the exe directly. These are fairly simple applications and there are no conditional branches when the application starts. But every time I run it, the amount of RAM varies from 6MB to 16MB.

I know this at the small end of use anyway, but I'm wondering why this is happening.

Edit: To give a little more clarification as to what the app actually does.
This is a WinForm project.
It connects to the database using sqlclient to retrieve the list of servers.
Based on this list, a series of buttons are created to start and stop the service on these servers.
Using the System.Timers class to check the status of services on these servers every 20 seconds.
Applications at this point are there and wait for user input through one of the button clicks to start / stop the service.

+2


a source to share


3 answers


The trick is that the amount of RAM listed in the task schedule is not the amount of RAM used by your application. This is most likely the amount of RAM reserved for use by your application.

Remember, with managed frameworks like .Net, you are not requesting or releasing memory directly. Rather, the garbage collector manages the memory for you. The amount of memory reserved for your application at a given time can vary and depends on many different factors, including the memory pressure created by other programs at that time.



Think of it this way: If you need 10MB of RAM for your application, is it faster to request and return it to the operating system 1MB at a time for more than 10 requests / releases, or reserve a block at a time with one request / release? Now expand that to a scenario where you don't know exactly how much RAM you will need, only that is somewhere around 10MB. Also, on your computer the 1 GB sits there is not used. Of course, the best thing to do is grab a chunk of good amount of available RAM. Even 20 or 30 MB would not be unreasonable in relation to the ram sitting there unused, because the unused RAM lost performance.

If your system later starts to feel some memory pressure, then .Net can easily bring some RAM back into the system. This is one way that managed languages ​​can sometimes provide better performance than languages ​​like C ++ with traditional memory management: a garbage collector that can easily take into account all system state when allocating memory.

+6


a source


What are you using to determine how much memory is "in use". Even with normal applications, Windows will aggressively allocate unused memory up front, and .NET applications have an even harder time in how much memory is actually being used, and how much Windows is just using so that it is instantly available when needed. If another application actually requests memory, this reserved memory will be reassigned.



One way to check is to minify the application (at least on XP). If you look at memory usage in something like the Task Manager, you will notice that it resets immediately, eliminating the seemingly "random" amount.

+1


a source


This may be due to jitter, after the first boot, the jitter has already created a compiled version and it doesn't need to be run. In addition, you will need to provide us with more detailed information about the application and what kind of memory you have in mind.

0


a source







All Articles