473,396 Members | 2,052 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,396 software developers and data experts.

Memory Leaks?

Has anyone noticed memory leaks in their VB.NET Windows Forms apps? My app
definitely has some memory leaks, so I did a simple test to see if it was my
app or something about VB.NET.

I created a test app with 2 forms. Form1 has a command button with the
following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim x As New Form2
x.Show()
End Sub

Watching the memory usage, I see that the used memory goes up between 10-20K
when I click the button to show Form2. When I close Form2, the memory is
not reclaimed.

Is there something I need to do to reclaim memory when closing a form?

Thanks!
Nov 20 '05 #1
17 1430
Form.Dispose

Then it takes some time before GC cleans up

Regards
Fredrik Melin
"David Schwartz" <da**@hr-symphony.com> wrote in message
news:ez**************@TK2MSFTNGP09.phx.gbl...
Has anyone noticed memory leaks in their VB.NET Windows Forms apps? My app definitely has some memory leaks, so I did a simple test to see if it was my app or something about VB.NET.

I created a test app with 2 forms. Form1 has a command button with the
following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim x As New Form2
x.Show()
End Sub

Watching the memory usage, I see that the used memory goes up between 10-20K when I click the button to show Form2. When I close Form2, the memory is
not reclaimed.

Is there something I need to do to reclaim memory when closing a form?

Thanks!

Nov 20 '05 #2
"David Schwartz" <da**@hr-symphony.com> schrieb

Is there something I need to do to reclaim memory when closing a
form?


No.

http://msdn.microsoft.com/library/en...management.asp
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
Then why is the memory not completely reclaimed?

"Armin Zingler" <az*******@freenet.de> wrote in message
news:40***********************@news.freenet.de...
"David Schwartz" <da**@hr-symphony.com> schrieb

Is there something I need to do to reclaim memory when closing a
form?
No.

http://msdn.microsoft.com/library/en...management.asp

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
On top of that, Microsoft Task Manager doesn't really deal well with a
managed environment, in fact, it kinda sucks in general. When .NET releases
memory Task manager doesn't really catch it sometimes, or whats reported as
being released and really is sometimes varies.

With those other links given to you you will also see tht GC invokes about
once every 47 seconds... How this number came to be, I don't know, but
almost every GC test I see always results to about that number.

cooky..

You can always get your memory usage by using

GC.GetTotalMemory(False)

I use .NET Memory Profiler by scitech, great tool...

"David Schwartz" <da**@hr-symphony.com> wrote in message
news:ez**************@TK2MSFTNGP09.phx.gbl...
Has anyone noticed memory leaks in their VB.NET Windows Forms apps? My app definitely has some memory leaks, so I did a simple test to see if it was my app or something about VB.NET.

I created a test app with 2 forms. Form1 has a command button with the
following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim x As New Form2
x.Show()
End Sub

Watching the memory usage, I see that the used memory goes up between 10-20K when I click the button to show Form2. When I close Form2, the memory is
not reclaimed.

Is there something I need to do to reclaim memory when closing a form?

Thanks!

Nov 20 '05 #5
"David Schwartz" <da**@hr-symphony.com> schrieb
Then why is the memory not completely reclaimed?


Did you read the article?
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #6
Yes, I read the article, and basically it says that .NET handles all memory
management for me. The problem is that my little test program proves
otherwise - memory is not reclaimed when I close a form.

"Armin Zingler" <az*******@freenet.de> wrote in message
news:40*********************@news.freenet.de...
"David Schwartz" <da**@hr-symphony.com> schrieb
Then why is the memory not completely reclaimed?


Did you read the article?
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #7
Did you read my comments? basically, task manager is a P.O.S.
"David Schwartz" <da**@hr-symphony.com> wrote in message
news:ex**************@TK2MSFTNGP11.phx.gbl...
Yes, I read the article, and basically it says that .NET handles all memory management for me. The problem is that my little test program proves
otherwise - memory is not reclaimed when I close a form.

"Armin Zingler" <az*******@freenet.de> wrote in message
news:40*********************@news.freenet.de...
"David Schwartz" <da**@hr-symphony.com> schrieb
Then why is the memory not completely reclaimed?


Did you read the article?
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


Nov 20 '05 #8
* "David Schwartz" <da**@hr-symphony.com> scripsit:
Yes, I read the article, and basically it says that .NET handles all memory
management for me. The problem is that my little test program proves
otherwise - memory is not reclaimed when I close a form.


That's by design. The GC will release the memory if the system needs
memory. Don't worry about that!

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #9
I see the same results by using System.GC.GetTotalMemory... Memory is not
completely reclaimed.
"CJ Taylor" <[cege] at [tavayn] dit commmmm> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Did you read my comments? basically, task manager is a P.O.S.
"David Schwartz" <da**@hr-symphony.com> wrote in message
news:ex**************@TK2MSFTNGP11.phx.gbl...
Yes, I read the article, and basically it says that .NET handles all

memory
management for me. The problem is that my little test program proves
otherwise - memory is not reclaimed when I close a form.

"Armin Zingler" <az*******@freenet.de> wrote in message
news:40*********************@news.freenet.de...
"David Schwartz" <da**@hr-symphony.com> schrieb
> Then why is the memory not completely reclaimed?

Did you read the article?
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html



Nov 20 '05 #10
http://www.scitech.se/memprofiler/

go here.

find out why.

"David Schwartz" <da**@hr-symphony.com> wrote in message
news:OO**************@TK2MSFTNGP10.phx.gbl...
I see the same results by using System.GC.GetTotalMemory... Memory is not
completely reclaimed.
"CJ Taylor" <[cege] at [tavayn] dit commmmm> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Did you read my comments? basically, task manager is a P.O.S.
"David Schwartz" <da**@hr-symphony.com> wrote in message
news:ex**************@TK2MSFTNGP11.phx.gbl...
Yes, I read the article, and basically it says that .NET handles all

memory
management for me. The problem is that my little test program proves
otherwise - memory is not reclaimed when I close a form.

"Armin Zingler" <az*******@freenet.de> wrote in message
news:40*********************@news.freenet.de...
> "David Schwartz" <da**@hr-symphony.com> schrieb
> > Then why is the memory not completely reclaimed?
>
> Did you read the article?
>
>
> --
> Armin
>
> How to quote and why:
> http://www.plig.net/nnq/nquote.html
> http://www.netmeister.org/news/learn2quote.html
>



Nov 20 '05 #11
CJ,

Can't find this tool on SciTech's website. Is www.scitechsoft.com correct?

Raymond Lewallen

"CJ Taylor" <[cege] at [tavayn] dit commmmm> wrote in message
news:#A**************@tk2msftngp13.phx.gbl...
On top of that, Microsoft Task Manager doesn't really deal well with a
managed environment, in fact, it kinda sucks in general. When .NET releases memory Task manager doesn't really catch it sometimes, or whats reported as being released and really is sometimes varies.

With those other links given to you you will also see tht GC invokes about
once every 47 seconds... How this number came to be, I don't know, but
almost every GC test I see always results to about that number.

cooky..

You can always get your memory usage by using

GC.GetTotalMemory(False)

I use .NET Memory Profiler by scitech, great tool...

"David Schwartz" <da**@hr-symphony.com> wrote in message
news:ez**************@TK2MSFTNGP09.phx.gbl...
Has anyone noticed memory leaks in their VB.NET Windows Forms apps? My app
definitely has some memory leaks, so I did a simple test to see if it was my
app or something about VB.NET.

I created a test app with 2 forms. Form1 has a command button with the
following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim x As New Form2
x.Show()
End Sub

Watching the memory usage, I see that the used memory goes up between

10-20K
when I click the button to show Form2. When I close Form2, the memory

is not reclaimed.

Is there something I need to do to reclaim memory when closing a form?

Thanks!


Nov 20 '05 #12
http://www.scitech.se/memprofiler/

"Raymond Lewallen" <Ra******************@nospam.faa.gov> wrote in message
news:uK*************@TK2MSFTNGP10.phx.gbl...
CJ,

Can't find this tool on SciTech's website. Is www.scitechsoft.com correct?
Raymond Lewallen

"CJ Taylor" <[cege] at [tavayn] dit commmmm> wrote in message
news:#A**************@tk2msftngp13.phx.gbl...
On top of that, Microsoft Task Manager doesn't really deal well with a
managed environment, in fact, it kinda sucks in general. When .NET

releases
memory Task manager doesn't really catch it sometimes, or whats reported

as
being released and really is sometimes varies.

With those other links given to you you will also see tht GC invokes about
once every 47 seconds... How this number came to be, I don't know, but
almost every GC test I see always results to about that number.

cooky..

You can always get your memory usage by using

GC.GetTotalMemory(False)

I use .NET Memory Profiler by scitech, great tool...

"David Schwartz" <da**@hr-symphony.com> wrote in message
news:ez**************@TK2MSFTNGP09.phx.gbl...
Has anyone noticed memory leaks in their VB.NET Windows Forms apps? My
app
definitely has some memory leaks, so I did a simple test to see if it

was
my
app or something about VB.NET.

I created a test app with 2 forms. Form1 has a command button with

the following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As New Form2
x.Show()
End Sub

Watching the memory usage, I see that the used memory goes up between

10-20K
when I click the button to show Form2. When I close Form2, the memory

is not reclaimed.

Is there something I need to do to reclaim memory when closing a form?

Thanks!



Nov 20 '05 #13
Nevermind, you just posted the link elsewhere in this thread. Thanks.

"Raymond Lewallen" <Ra******************@nospam.faa.gov> wrote in message
news:uK*************@TK2MSFTNGP10.phx.gbl...
CJ,

Can't find this tool on SciTech's website. Is www.scitechsoft.com correct?
Raymond Lewallen

"CJ Taylor" <[cege] at [tavayn] dit commmmm> wrote in message
news:#A**************@tk2msftngp13.phx.gbl...
On top of that, Microsoft Task Manager doesn't really deal well with a
managed environment, in fact, it kinda sucks in general. When .NET

releases
memory Task manager doesn't really catch it sometimes, or whats reported

as
being released and really is sometimes varies.

With those other links given to you you will also see tht GC invokes about
once every 47 seconds... How this number came to be, I don't know, but
almost every GC test I see always results to about that number.

cooky..

You can always get your memory usage by using

GC.GetTotalMemory(False)

I use .NET Memory Profiler by scitech, great tool...

"David Schwartz" <da**@hr-symphony.com> wrote in message
news:ez**************@TK2MSFTNGP09.phx.gbl...
Has anyone noticed memory leaks in their VB.NET Windows Forms apps? My
app
definitely has some memory leaks, so I did a simple test to see if it

was
my
app or something about VB.NET.

I created a test app with 2 forms. Form1 has a command button with

the following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As New Form2
x.Show()
End Sub

Watching the memory usage, I see that the used memory goes up between

10-20K
when I click the button to show Form2. When I close Form2, the memory

is not reclaimed.

Is there something I need to do to reclaim memory when closing a form?

Thanks!



Nov 20 '05 #14
Ah, now that makes sense! I just tested this out and confirmed that the
memory is indeed released as the system needs it (when I open up many more
applications).

Thanks!

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:c5************@ID-208219.news.uni-berlin.de...
* "David Schwartz" <da**@hr-symphony.com> scripsit:
Yes, I read the article, and basically it says that .NET handles all memory management for me. The problem is that my little test program proves
otherwise - memory is not reclaimed when I close a form.


That's by design. The GC will release the memory if the system needs
memory. Don't worry about that!

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #15
Someone posted a solution in another group:

System.GC.WaitForPendingFinalizers()
System.GC.Collect()

This problem becames really bad when you deal with graphics.

David Schwartz wrote:
Has anyone noticed memory leaks in their VB.NET Windows Forms apps? My app
definitely has some memory leaks, so I did a simple test to see if it was my
app or something about VB.NET.

I created a test app with 2 forms. Form1 has a command button with the
following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim x As New Form2
x.Show()
End Sub

Watching the memory usage, I see that the used memory goes up between 10-20K
when I click the button to show Form2. When I close Form2, the memory is
not reclaimed.

Is there something I need to do to reclaim memory when closing a form?

Thanks!


Nov 20 '05 #16
You really shoulnd't ever call the garbage collector...
"Arcer P" <No@Spam.Com> wrote in message
news:Ol**************@TK2MSFTNGP10.phx.gbl...
Someone posted a solution in another group:

System.GC.WaitForPendingFinalizers()
System.GC.Collect()

This problem becames really bad when you deal with graphics.

David Schwartz wrote:
Has anyone noticed memory leaks in their VB.NET Windows Forms apps? My app definitely has some memory leaks, so I did a simple test to see if it was my app or something about VB.NET.

I created a test app with 2 forms. Form1 has a command button with the
following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim x As New Form2
x.Show()
End Sub

Watching the memory usage, I see that the used memory goes up between 10-20K when I click the button to show Form2. When I close Form2, the memory is not reclaimed.

Is there something I need to do to reclaim memory when closing a form?

Thanks!

Nov 20 '05 #17
Hi CJ,

Some people/organizations like it when a program does a lot of processes
that do nothing.

Than they can say that the process they have are very heavy.
I think we can give this answer to someone who needs that the next time.

Function multiply(byval a as integer, byval b as integer) byval as integer
dim c = 0
if b > a then ' to be sure the longest way is taken
For i as integer = 1 to b
c = c + a
System.GC.WaitForPendingFinalizers()
System.GC.Collect()
next
else
For i as integer = 1 to a
c = c + b
System.GC.WaitForPendingFinalizers()
System.GC.Collect()
next
(I know that there should be a -1 to b also in)

However this is very good programming in a special class, I see it before me
never more use
c = a*b however only
c = multiply(a,b)

And no memory leaks of course for this calculation

Before someone thinks it, this is not a serious solution.
Cor.

Nov 20 '05 #18

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

Similar topics

4
by: Maurice | last post by:
Hi there, I'm experiencing big memory problems on my webserver. First on an old RedHat 7.2 system, now on an other fresh installed Suse 8.2 system: Linux version 2.4.20-4GB...
0
by: Steve Binney | last post by:
My code makes synchronous HttpWebRequest and HttpRebResponse calls. In VS 2003, I am getting memory leaks and event handle leaks. I am closing all streams and using "using"statements. I have...
4
by: Morten Aune Lyrstad | last post by:
Ok, now I'm officially confused. I have a large project going, which uses a win32 ui library I am developing myself. And I'm getting weird memory leaks. I don't know if I can explain what is going...
2
by: Generic Usenet Account | last post by:
I have been using STL for a long time now, without any problems. Recently we generated a purification report on our software using Rational Purify, and we found some memory leaks. My colleague...
8
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
0
by: Frank Lopez | last post by:
Does anyone know if Microsoft generated a whitepaper on this topic? Does anyone know what the solution is? (meaning, eliminate the leak problem -- I am seeing three memory leaks from...
4
by: ali.jan | last post by:
Hi, It is trivial to load an assembly in a new Application Domain. Is there any way of loading an assembly in a new process? I tried using the Process class like this: Process p = new...
23
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
3
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". ...
16
by: graham.keellings | last post by:
hi, I'm looking for an open source memory pool. It's for use on an embedded system, if that makes any difference. Something with garbage collection/defragmentation would be nice. It should have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.