Reducing Memory Usage of .Net Applications

Reducing memory usage of .NET applications?


  1. You might want to check out Stack Overflow question .NET EXE memory footprint.
  2. The MSDN blog post Working set != actual memory footprint is all about demystifying the working set, process memory and how to perform accurate calculations on your total in-RAM consumption.

I will not say that you should ignore the memory footprint of your application -- obviously, smaller and more efficient does tend to be desirable. However, you should consider what your actual needs are.

If you are writing a standard Windows Forms and WPF client applications which is destined to run on an individual's PC, and is likely to be the primary application in which the user operates, you can get away with being more lackadaisical about memory allocation. (So long as it all gets deallocated.)

However, to address some folks here who say not to worry about it: If you're writing a Windows Forms application which will be running in a terminal services environment, on a shared server possibly utilized by 10, 20 or more users, then yes, you absolutely must consider memory usage. And you will need to be vigilant. The best way to address this is with good data structure design and by following best practices regarding when and what you allocate.

High memory usage by ASP.NET applications

Removing all Telerik Kendo MVC references (dll and such) fixed our problems. If we run the application without, all our memory problems are gone and we see normal memory use.

Basically: it was an external library causing high memory use.

How to reduce memory consumption when app is minimized for x amount of time

The symptomes you describe seem to indicate that your machine lacks physical memory. When you minimize an application and activate another, the minimized application has many of its memory pages swapped out to disk. When you activate back the application, pages belonging to other applications are swapped out to disk and the perviously swapped out pages belonging to the application you just activated are swapped into physical memory, taking a long time due to the relatively slowness of the hard drive. Solution: Add more RAM, it's relatively cheap. If your O.S. is 32 bit, you can go up to 4GB. If your O.S. is 64 bit, whatever your motherboard supports is the limit.

How to reduce commit size of memory in vb.net application?

The .NET garbage collector does not guarantee to free memory in any particular timeframe. It might, for example, wait until the memory is needed before freeing up used memory.

You can force a garbage collection by calling

GC.Collect 

These articles explain things in a bit more depth:

http://msdn.microsoft.com/en-us/library/ms973837.aspx

http://www.simple-talk.com/dotnet/.net-framework/understanding-garbage-collection-in-.net/

High memory usage by ASP.NET applications

Removing all Telerik Kendo MVC references (dll and such) fixed our problems. If we run the application without, all our memory problems are gone and we see normal memory use.

Basically: it was an external library causing high memory use.

.NET Application Memory usage grow over time, memory leak or not?

Task Manager shows you the amount of memory belonging to the application that happens to be paged into real memory at the time (the working set). This is probably what you're seeing.

If you look instead at the "Private Bytes" used by your process, this should give you a better indication of the amount of memory used. This value doesn't change when the process working set is trimmed. There is more information in this Microsoft KB article.

You can manually reduce your app's working set by using the Win32 API call SetProcessWorkingSetSize(GetCurrentProcess(), -1, -1).

This is what Windows will do anyway when the system runs low on memory, but controlling when this happens yourself lets you strip your .NET application's working set to its minimum size for investigation purposes.

BTW, be very careful about calling GC.Collect().



Related Topics



Leave a reply



Submit