Small winform app uses lots of memory

A

Aaron Prohaska

Is it normal that a very small single form winforms app uses 20mb of
memory or more? I have a form with 16 data bound text boxes and two data
grids. When the app is first opened the text boxes and all bound to an
empty strongly typed dataset so that the user can enter data and create
a record. Does anyone know why this initial form state would use 15mb of
memory. I also see that as the app just sits open without being used its
memory use is slowing climbing with leads me to believe there is a
memory leak somewhere.

Regards,

Aaron Prohaska

-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-
Wrench Science Inc.
http://www.wrenchScience.com/
Phone: 510.841.4748 x206
Fax: 510.841.4708
-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-
 
H

Herfried K. Wagner [MVP]

* Aaron Prohaska said:
Is it normal that a very small single form winforms app uses 20mb of
memory or more? I have a form with 16 data bound text boxes and two
data grids. When the app is first opened the text boxes and all bound
to an empty strongly typed dataset so that the user can enter data and
create a record. Does anyone know why this initial form state would
use 15mb of memory.

That's "normal".
I also see that as the app just sits open without
being used its memory use is slowing climbing with leads me to believe
there is a memory leak somewhere.

This can be normal, but it can be a leak too. Don't forget to dispose
objects and call 'GC.Collect' to force the GC to run for test purposes.
 
J

Justin Rogers

I also see that as the app just sits open without
This can be normal, but it can be a leak too. Don't forget to dispose
objects and call 'GC.Collect' to force the GC to run for test purposes.

The general reason for climbing memory is allocation as a result of the
underlying Windows Forms framework. Various portions of the Windows
Forms message pump allocate objects each time the loop is run and
this pump is active irregardless of whether or not your application is doing
anything.

In the current version of the CLR there is no way to place pressure
on the GC or apply a memory ceiling, so conceptually the GC would allow
the memory to grow until the system was exhausted of resources before it
begins aggresively collecting. Calling GC.Collect manually is a possible
option, but it short-circuits the default GC behavior and may cause problems
with future versions of the CLR. There are definitely enhancements to the GC
that will be present in Whidbey to help mitigate the current memory growth
trend you see in Windows Forms application.
 
A

AlexS

You can use SetProcessWorkingSetSize Win32 API to force unused memory to
disk, which will make app to appear using less memory. The only drawback you
will see - some increased disk activity when application is swapped back if
activated and related delay. So, even if you can't pressure GC, you can
pressure Windows to move out some of app.

HTH
Alex
 
H

Herfried K. Wagner [MVP]

* "AlexS said:
You can use SetProcessWorkingSetSize Win32 API to force unused memory to
disk, which will make app to appear using less memory. The only drawback you
will see - some increased disk activity when application is swapped back if
activated and related delay. So, even if you can't pressure GC, you can
pressure Windows to move out some of app.

That's what Windows is doing when an application is minimized.
 
A

Aaron Prohaska

Herfried said:
That's what Windows is doing when an application is minimized.

Sorry about my not responding to this. I seem to have forgotten about
this. Anyway, This memory issue really seems like a problem for anyone
developing a large win app. The client machines that the app runs on
would have to have a large amount a memory to run the app. What do you
do when the user leaves the app open and running for a day? The app
could use up all the memory in the machine. Do I have to tell my users
that they can't leave the app open for an extended period of time? Most
of machines my app is going to run on have 512MB ram which I think
should be ok. The problem I see is that the app is quite large and I can
see the users leaving the app open for days at a time. Does anyone have
any suggestions about dealing with this?

Regards,

Aaron Prohaska

-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-
Wrench Science Inc.
http://www.wrenchScience.com/
Phone: 510.841.4748 x206
Fax: 510.841.4708
-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-
 
A

AlexS

Hi, Aaron

usually this is problem of application. If resources are released properly
and dangerous operations, which produce memory leaks, are avoided - this is
not the issue. Even if GC is not ideal right now, there are ways to make
code really safe in this respect. If application behaves badly - you might
run out of 512MB fairly quickly. So it really depends how code is written.


HTH
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top