On Fri, 10 Sep 2004 09:17:18 +0300, Nikolay Petrov wrote:
You are right, after minimize the app and the maximize it again the memory
usage drop.
But after that things are the same - every click on form controls takes
memory and after some time the memory usage increases significantly. How to
prevent this behavior? I am not going to tell users to minimize thier app
from time to time. It's kind of silly.
You don't have to... The behavior I was pointing out is not specific to
..NET applications. That is the way windows memory allocation works. A
process when first started is granted a larger working set then it is
expected to be used (to speed up future memory allocations). When the app
is minimized the OS reduces that working set - since the application is no
longer being used by the user.
Now, as for the growing memory... Again, you've got two main forces at
work here. You have the fact that .NET is a gc based system - which means
that memory for objects is not immediately returned to the OS. Objects are
reclaimed during a gc cycle, which is triggered when memory pressure
reaches a certain threashold. The second main factor is again - windows
memory managment. When memory that is being used by an application is
returned to the system - the, system does not necessarily remove it from
the processes working set. Again, this is because the OS figures the
process might want to allocate memory again - so, it can just reuse that
which is already allocated. If the OS needs the memory for other
applications, it will take it...
Basically, what I'm saying is that though, in general .NET apps have a
larger foot - it is not something you should be worrying about unless it is
continuing to grow without bounds and causing applications to crash due to
resource errors - this situation would be a result of a resource leak
(which is usually the result of improper management of unmanaged
resources). And in that case, you would probably want to employ a
profiling tool of some sort to help you locate the cause of the problem.
--
Tom Shelton [MVP]