473,385 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Winforms and memory usage

I'm developing a WinForms application. It slowly eats up memory, one
client reported that it took 200MB or more, and finnaly crashed. I
myself noticed it's common to use up 30MB memory, but if I minimize it
(all the Forms will Hide, only a NotifyIcon is shown at the System
Notification Area), the memory usage comes down to 8MB immediately.
After that, even if I show the Forms again, it uses only 8MB memory.
Do I have another way to programmly cut down the memory usage, other
than Hide/Show all the Forms manually?

Thanks!

Oct 12 '07 #1
9 4160

It sounds like you have a legitimate memory leak. You'll need to track this
down.

It also sounds like you need to run this from time to time:
http://www.jdconley.com/blog/archive...anymemory.aspx

There's alot of debate about that 2nd one, and you should give it some
though before using it, but if your users are whining that it takes too much
memory, that'll shut them up... :)

--
Chris Mullins

"deerchao" <de******@gmail.comwrote in message
news:11**********************@z24g2000prh.googlegr oups.com...
I'm developing a WinForms application. It slowly eats up memory, one
client reported that it took 200MB or more, and finnaly crashed. I
myself noticed it's common to use up 30MB memory, but if I minimize it
(all the Forms will Hide, only a NotifyIcon is shown at the System
Notification Area), the memory usage comes down to 8MB immediately.
After that, even if I show the Forms again, it uses only 8MB memory.
Do I have another way to programmly cut down the memory usage, other
than Hide/Show all the Forms manually?

Thanks!

Oct 12 '07 #2
Jay
Do non-.net applications (eg VB6, MS VS6, C++ Builder, Delphi) have the same
"problem" of appearing to use a lot of memory?
"Chris Mullins [MVP - C#]" <cm******@yahoo.comwrote in message
news:OQ*************@TK2MSFTNGP02.phx.gbl...

It sounds like you have a legitimate memory leak. You'll need to track this
down.

It also sounds like you need to run this from time to time:
http://www.jdconley.com/blog/archive...anymemory.aspx

There's alot of debate about that 2nd one, and you should give it some
though before using it, but if your users are whining that it takes too much
memory, that'll shut them up... :)

Oct 12 '07 #3
In my experience, .Net WinForms is the worst (best?) at doing an
impersonation of a bloated sow.

In general, Winforms does quite a bit of things very well, but conservation
of desktop memory isn't on that list.

--
Chris Mullins

"Jay" <-wrote in message news:u4**************@TK2MSFTNGP06.phx.gbl...
Do non-.net applications (eg VB6, MS VS6, C++ Builder, Delphi) have the
same
"problem" of appearing to use a lot of memory?
"Chris Mullins [MVP - C#]" <cm******@yahoo.comwrote in message
news:OQ*************@TK2MSFTNGP02.phx.gbl...

It sounds like you have a legitimate memory leak. You'll need to track
this
down.

It also sounds like you need to run this from time to time:
http://www.jdconley.com/blog/archive...anymemory.aspx

There's alot of debate about that 2nd one, and you should give it some
though before using it, but if your users are whining that it takes too
much
memory, that'll shut them up... :)

Oct 12 '07 #4
The best thing to do to see if you really are leaking objects is to get a
memory dump of your application at a time you think it is using an excess
of memory. Then check and see if there are a lot of objects still held
around in memory that shouldn't be there. You can use the Debugging Tools
for Windows to get that and the sos.dll extension that comes with .NET 2.0.
There are quite a few articles out on the web that can help you with this.

You can get the 32bit version from here:
http://www.microsoft.com/whdc/devtoo...nstallx86.mspx

-------------------------------------
Chris Alton, Microsoft Corp.
SQL Server Developer Support Engineer
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "Chris Mullins [MVP - C#]" <cm******@yahoo.com>
References: <11**********************@z24g2000prh.googlegroups .com>
<OQ*************@TK2MSFTNGP02.phx.gbl>
<u4**************@TK2MSFTNGP06.phx.gbl>
Subject: Re: Winforms and memory usage
Date: Fri, 12 Oct 2007 13:43:36 -0700
Lines: 32

In my experience, .Net WinForms is the worst (best?) at doing an
impersonation of a bloated sow.

In general, Winforms does quite a bit of things very well, but
conservation
of desktop memory isn't on that list.

--
Chris Mullins

"Jay" <-wrote in message news:u4**************@TK2MSFTNGP06.phx.gbl...
Do non-.net applications (eg VB6, MS VS6, C++ Builder, Delphi) have the
same
"problem" of appearing to use a lot of memory?
"Chris Mullins [MVP - C#]" <cm******@yahoo.comwrote in message
news:OQ*************@TK2MSFTNGP02.phx.gbl...

It sounds like you have a legitimate memory leak. You'll need to track
this
down.

It also sounds like you need to run this from time to time:
http://www.jdconley.com/blog/archive...tothinkwedontu
seanymemory.aspx

There's alot of debate about that 2nd one, and you should give it some
though before using it, but if your users are whining that it takes too
much
memory, that'll shut them up... :)


Oct 12 '07 #5
Having spent far, far too much time at this, I would recommend two products
over SOS:

- SciTech Memory Profiler is excellent. They have a 14 day free trial.
- RedGate ANTS Memory Profiler is also excellent. They also have a trial.

When I do seminars or mentoring on this, I always start with these products,
and only revert to Son of Strike and WinDbg as a very last resort. The
learning curve on SOS is brutal, and most devs won't ever get through it.

The learning curve for SciTech is about a day, and it's extremely powerfull.
Amazingly so.

The learning curve for ANTS is a few hours, but it's nowhere near as
powerfull as SciTech.

--
Chris Mullins

"Chris Alton [MSFT]" <ca****@online.microsoft.comwrote in message
news:zE**************@TK2MSFTNGHUB02.phx.gbl...
The best thing to do to see if you really are leaking objects is to get a
memory dump of your application at a time you think it is using an excess
of memory. Then check and see if there are a lot of objects still held
around in memory that shouldn't be there. You can use the Debugging Tools
for Windows to get that and the sos.dll extension that comes with .NET
2.0.
There are quite a few articles out on the web that can help you with this.

You can get the 32bit version from here:
http://www.microsoft.com/whdc/devtoo...nstallx86.mspx

-------------------------------------
Chris Alton, Microsoft Corp.
SQL Server Developer Support Engineer
This posting is provided "AS IS" with no warranties, and confers no
rights.
--------------------
>From: "Chris Mullins [MVP - C#]" <cm******@yahoo.com>
References: <11**********************@z24g2000prh.googlegroups .com>
<OQ*************@TK2MSFTNGP02.phx.gbl>
<u4**************@TK2MSFTNGP06.phx.gbl>
>Subject: Re: Winforms and memory usage
Date: Fri, 12 Oct 2007 13:43:36 -0700
Lines: 32

In my experience, .Net WinForms is the worst (best?) at doing an
impersonation of a bloated sow.

In general, Winforms does quite a bit of things very well, but
conservation
>of desktop memory isn't on that list.

--
Chris Mullins

"Jay" <-wrote in message news:u4**************@TK2MSFTNGP06.phx.gbl...
Do non-.net applications (eg VB6, MS VS6, C++ Builder, Delphi) have the
same
"problem" of appearing to use a lot of memory?
"Chris Mullins [MVP - C#]" <cm******@yahoo.comwrote in message
news:OQ*************@TK2MSFTNGP02.phx.gbl...

It sounds like you have a legitimate memory leak. You'll need to track
this
down.

It also sounds like you need to run this from time to time:
http://www.jdconley.com/blog/archive...tothinkwedontu
seanymemory.aspx
>
There's alot of debate about that 2nd one, and you should give it some
though before using it, but if your users are whining that it takes too
much
memory, that'll shut them up... :)



Oct 12 '07 #6
Hi,
Just a thought when profiling, allow sufficient time for the full
behaviour to be shown.
I went chasing a 'memory leak' where the Private bytes and Working Set
usage went up for several hours for no good reason I could see.
They finally levelled out then came down again. Then went up again
etc.
Took a couple of days of this wobbling behaviour before I accepted
that there was no leak.
Bob
On Fri, 12 Oct 2007 14:21:34 -0700, "Chris Mullins [MVP - C#]"
<cm******@yahoo.comwrote:
>Having spent far, far too much time at this, I would recommend two products
over SOS:

- SciTech Memory Profiler is excellent. They have a 14 day free trial.
- RedGate ANTS Memory Profiler is also excellent. They also have a trial.

When I do seminars or mentoring on this, I always start with these products,
and only revert to Son of Strike and WinDbg as a very last resort. The
learning curve on SOS is brutal, and most devs won't ever get through it.

The learning curve for SciTech is about a day, and it's extremely powerfull.
Amazingly so.

The learning curve for ANTS is a few hours, but it's nowhere near as
powerfull as SciTech.
Oct 15 '07 #7
That would be the Garbage Collector at work. The garbage collector won't
run until it deems it necessary (or you force it in your code by calling
GC.Collect). So it is possible your .NET app can use up ~300MB of RAM but
in reality that amount is much lower and the garbage collector has not run
yet. If you wait long enough the garbage collector should kick off and drop
the memory usage of your app into the normal usage range.

-------------------------------------
Chris Alton, Microsoft Corp.
SQL Server Developer Support Engineer
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: bob clegg <cu**********@remooove.xtra.co.nz>
Subject: Re: Winforms and memory usage
Date: Mon, 15 Oct 2007 23:13:48 +1300
Message-ID: <am********************************@4ax.com>
References: <11**********************@z24g2000prh.googlegroups .com>
<OQ*************@TK2MSFTNGP02.phx.gbl>
<u4**************@TK2MSFTNGP06.phx.gbl>
<#x**************@TK2MSFTNGP04.phx.gbl>
<zE**************@TK2MSFTNGHUB02.phx.gbl>
<Oz**************@TK2MSFTNGP03.phx.gbl>
>
Hi,
Just a thought when profiling, allow sufficient time for the full
behaviour to be shown.
I went chasing a 'memory leak' where the Private bytes and Working Set
usage went up for several hours for no good reason I could see.
They finally levelled out then came down again. Then went up again
etc.
Took a couple of days of this wobbling behaviour before I accepted
that there was no leak.
Bob
On Fri, 12 Oct 2007 14:21:34 -0700, "Chris Mullins [MVP - C#]"
<cm******@yahoo.comwrote:
Having spent far, far too much time at this, I would recommend two
products
over SOS:

- SciTech Memory Profiler is excellent. They have a 14 day free trial.
- RedGate ANTS Memory Profiler is also excellent. They also have a trial.

When I do seminars or mentoring on this, I always start with these
products,
and only revert to Son of Strike and WinDbg as a very last resort. The
learning curve on SOS is brutal, and most devs won't ever get through it.

The learning curve for SciTech is about a day, and it's extremely
powerfull.
Amazingly so.

The learning curve for ANTS is a few hours, but it's nowhere near as
powerfull as SciTech.
Oct 17 '07 #8
"Chris Alton [MSFT]" <ca****@online.microsoft.comwrote in message
news:B%******************@TK2MSFTNGHUB02.phx.gbl.. .
That would be the Garbage Collector at work. The garbage collector won't
run until it deems it necessary (or you force it in your code by calling
GC.Collect). So it is possible your .NET app can use up ~300MB of RAM but
in reality that amount is much lower and the garbage collector has not run
yet. If you wait long enough the garbage collector should kick off and
drop
the memory usage of your app into the normal usage range.
Sorry to correct you, but this is not true, the GC kicks in when the gen0
threshold has been reached, this threshold varies with the version of the
CLR ,the version of the GC (server/workstation) the size of the L2 data
cache and the allocation frequency. In general less than a few of MB but
certainly much less than ~300MB. Just write a small program that creates a
bunch of objects and watch the Gen0 collection count with perfmon while it
runs.

Willy.

Oct 17 '07 #9
Please read my post carefully before jumping to conclusions.

I stated below that it is "possible" your .NET app can use up to 300MB of
RAM (as viewed in task manager) not that 300MB is the kick in point for the
Garbage Collector to run. Try loading up multiple large DataSets with
around 50,000 rows on a button click and you'll certainly see the memory
usage of the app exceed 300MB.
So it is possible your .NET app can use up ~300MB of RAM but
in reality that amount is much lower and the garbage collector has not
run
yet. If you wait long enough the garbage collector should kick off and
drop the memory usage of your app into the normal usage range.

-------------------------------------
Chris Alton, Microsoft Corp.
SQL Server Developer Support Engineer
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "Willy Denoyette [MVP]" <wi*************@telenet.be>
References: <11**********************@z24g2000prh.googlegroups .com>
<OQ*************@TK2MSFTNGP02.phx.gbl>
<u4**************@TK2MSFTNGP06.phx.gbl>
<#x**************@TK2MSFTNGP04.phx.gbl>
<zE**************@TK2MSFTNGHUB02.phx.gbl>
<Oz**************@TK2MSFTNGP03.phx.gbl>
<am********************************@4ax.com>
<B#**************@TK2MSFTNGHUB02.phx.gbl>
In-Reply-To: <B#**************@TK2MSFTNGHUB02.phx.gbl>
Subject: Re: Winforms and memory usage
Date: Wed, 17 Oct 2007 21:50:27 +0200
Lines: 23
MIME-Version: 1.0
Content-Type: text/plain;
format=flowed;
charset="Windows-1252";
reply-type=original
Content-Transfer-Encoding: 7bit

"Chris Alton [MSFT]" <ca****@online.microsoft.comwrote in message
news:B%******************@TK2MSFTNGHUB02.phx.gbl.. .
That would be the Garbage Collector at work. The garbage collector won't
run until it deems it necessary (or you force it in your code by calling
GC.Collect). So it is possible your .NET app can use up ~300MB of RAM
but
in reality that amount is much lower and the garbage collector has not
run
yet. If you wait long enough the garbage collector should kick off and
drop
the memory usage of your app into the normal usage range.

Sorry to correct you, but this is not true, the GC kicks in when the gen0
threshold has been reached, this threshold varies with the version of the
CLR ,the version of the GC (server/workstation) the size of the L2 data
cache and the allocation frequency. In general less than a few of MB but
certainly much less than ~300MB. Just write a small program that creates
a
bunch of objects and watch the Gen0 collection count with perfmon while
it
runs.

Willy.

Oct 22 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: rbt | last post by:
Would a Python process consume more memory on a PC with lots of memory? For example, say I have the same Python script running on two WinXP computers that both have Python 2.4.0. One computer has...
2
by: tomvr | last post by:
Hello I have noticed some 'weird' memory usage in a vb.net windows app The situation is as follows I have an app (heavy on images) with 2 forms (actually there are more forms and on starting...
2
by: Jarvis | last post by:
I've made a testing program to test the memory usage of some Data Forms. I create a MDI parent form with one single MDI child form, which is a Data Form generated by .NET Data Form Wizard. To...
3
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
7
by: George Gre | last post by:
Hi, I wrote a c# programme that listens to incoming TCP requests and services them. This programme is meant to be running as long as the server its installed on is running. So we assume for...
20
by: Philip Carnstam | last post by:
How come .Net applications use so much memory? Every application I compile uses at least 10 MB of memory, even the ones consisting of only a form and nothing else. If I minimize them though the...
4
by: RH | last post by:
Hi, I am building a windows application that has a feature that retrieves a set of records when a button is clicked. When the records are being retrieved I experience a complete system...
2
by: jld | last post by:
Hi, I developed an asp.net based eCommerce Website for a client and it is hosted at discount asp. The site is quite interactive, queries a database a lot and uses ajax.asp.net to spice up...
16
by: dantz | last post by:
Hi everyone, I will be supporting 5 languages in my app. And I'm not sure if my memory usage will increase a lot if I put all the image resources inside the resource file. Currently the images...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.