|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Memory Leak in DataSetsI am using VB 2005 and have been having problems with memory usage in services. After some investigation I think I have found that DataSets leak memory! So I created a simple test 1) Create a new Windows Application 2) Added an Empty DataSet 3) Put a button on the form and then added this code. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click While True For k As Integer = 0 To 100000 Dim ds As New DataSet1 ds.Dispose() ds = Nothing Next GC.Collect() MsgBox((GC.GetTotalMemory(True) / 1024).ToString()) End While End Sub The Message box will tell me how much memory wasn't GCed and I get these results 2507K 4587K 7168K .... So my question is. Do DataSets leak memory? Or am I doing something wrong? BTW: I see no leak if I am in Release Mode, only in Debug, with or without the debugger. Then it's Visual Studio leaking memory... not the DataSet. ;)
-- Show quote____________________________________ William (Bill) Vaughn Author, Mentor, Consultant Microsoft MVP INETA Speaker www.betav.com/blog/billva www.betav.com Please reply only to the newsgroup so that others can benefit. This posting is provided "AS IS" with no warranties, and confers no rights. __________________________________ Visit www.hitchhikerguides.net to get more information on my latest book: Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ----------------------------------------------------------------------------------------------------------------------- "Gunnar Valur" <GunnarVa***@discussions.microsoft.com> wrote in message news:2C632526-94D8-4C69-87E0-3E72CF33073A@microsoft.com... > Hi, > > I am using VB 2005 and have been having problems with memory usage in > services. After some investigation I think I have found that DataSets > leak > memory! > > So I created a simple test > > 1) Create a new Windows Application > 2) Added an Empty DataSet > 3) Put a button on the form and then added this code. > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > While True > For k As Integer = 0 To 100000 > Dim ds As New DataSet1 > ds.Dispose() > ds = Nothing > Next > > GC.Collect() > MsgBox((GC.GetTotalMemory(True) / 1024).ToString()) > End While > End Sub > > The Message box will tell me how much memory wasn't GCed and I get these > results > > 2507K > 4587K > 7168K > ... > > So my question is. Do DataSets leak memory? Or am I doing something > wrong? > > BTW: I see no leak if I am in Release Mode, only in Debug, with or without > the debugger. > > > > No Because it leaks even if I run the program in Debug Mode and I just run
the exe file without Visual Studio. Show quote "William (Bill) Vaughn" wrote: > Then it's Visual Studio leaking memory... not the DataSet. ;) > > -- > ____________________________________ > William (Bill) Vaughn > Author, Mentor, Consultant > Microsoft MVP > INETA Speaker > www.betav.com/blog/billva > www.betav.com > Please reply only to the newsgroup so that others can benefit. > This posting is provided "AS IS" with no warranties, and confers no rights. > __________________________________ > Visit www.hitchhikerguides.net to get more information on my latest book: > Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) > and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) > ----------------------------------------------------------------------------------------------------------------------- > > "Gunnar Valur" <GunnarVa***@discussions.microsoft.com> wrote in message > news:2C632526-94D8-4C69-87E0-3E72CF33073A@microsoft.com... > > Hi, > > > > I am using VB 2005 and have been having problems with memory usage in > > services. After some investigation I think I have found that DataSets > > leak > > memory! > > > > So I created a simple test > > > > 1) Create a new Windows Application > > 2) Added an Empty DataSet > > 3) Put a button on the form and then added this code. > > > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > > System.EventArgs) Handles Button1.Click > > While True > > For k As Integer = 0 To 100000 > > Dim ds As New DataSet1 > > ds.Dispose() > > ds = Nothing > > Next > > > > GC.Collect() > > MsgBox((GC.GetTotalMemory(True) / 1024).ToString()) > > End While > > End Sub > > > > The Message box will tell me how much memory wasn't GCed and I get these > > results > > > > 2507K > > 4587K > > 7168K > > ... > > > > So my question is. Do DataSets leak memory? Or am I doing something > > wrong? > > > > BTW: I see no leak if I am in Release Mode, only in Debug, with or without > > the debugger. > > > > > > > > > > > Hi Gunnar,
I doubt it leaks memory, I'll try this code with a memory profiler... -- Show quoteMiha Markic [MVP C#, INETA Country Leader for Slovenia] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ "Gunnar Valur" <GunnarVa***@discussions.microsoft.com> wrote in message news:2C632526-94D8-4C69-87E0-3E72CF33073A@microsoft.com... > Hi, > > I am using VB 2005 and have been having problems with memory usage in > services. After some investigation I think I have found that DataSets > leak > memory! > > So I created a simple test > > 1) Create a new Windows Application > 2) Added an Empty DataSet > 3) Put a button on the form and then added this code. > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > While True > For k As Integer = 0 To 100000 > Dim ds As New DataSet1 > ds.Dispose() > ds = Nothing > Next > > GC.Collect() > MsgBox((GC.GetTotalMemory(True) / 1024).ToString()) > End While > End Sub > > The Message box will tell me how much memory wasn't GCed and I get these > results > > 2507K > 4587K > 7168K > ... > > So my question is. Do DataSets leak memory? Or am I doing something > wrong? > > BTW: I see no leak if I am in Release Mode, only in Debug, with or without > the debugger. > > > > I managed to use CLRProfiler on this and I see many MB of
System.WeakReference. My program isn't using any WeakReferences Show quote "Miha Markic [MVP C#]" wrote: > Hi Gunnar, > > I doubt it leaks memory, I'll try this code with a memory profiler... > > -- > Miha Markic [MVP C#, INETA Country Leader for Slovenia] > RightHand .NET consulting & development www.rthand.com > Blog: http://cs.rthand.com/blogs/blog_with_righthand/ > "Gunnar Valur" <GunnarVa***@discussions.microsoft.com> wrote in message > news:2C632526-94D8-4C69-87E0-3E72CF33073A@microsoft.com... > > Hi, > > > > I am using VB 2005 and have been having problems with memory usage in > > services. After some investigation I think I have found that DataSets > > leak > > memory! > > > > So I created a simple test > > > > 1) Create a new Windows Application > > 2) Added an Empty DataSet > > 3) Put a button on the form and then added this code. > > > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > > System.EventArgs) Handles Button1.Click > > While True > > For k As Integer = 0 To 100000 > > Dim ds As New DataSet1 > > ds.Dispose() > > ds = Nothing > > Next > > > > GC.Collect() > > MsgBox((GC.GetTotalMemory(True) / 1024).ToString()) > > End While > > End Sub > > > > The Message box will tell me how much memory wasn't GCed and I get these > > results > > > > 2507K > > 4587K > > 7168K > > ... > > > > So my question is. Do DataSets leak memory? Or am I doing something > > wrong? > > > > BTW: I see no leak if I am in Release Mode, only in Debug, with or without > > the debugger. > > > > > > > > > > Is this the actual code? How does this loop every stop? Where does True
get flipped to false? Show quote "Gunnar Valur" <GunnarVa***@discussions.microsoft.com> wrote in message news:2C632526-94D8-4C69-87E0-3E72CF33073A@microsoft.com... > Hi, > > I am using VB 2005 and have been having problems with memory usage in > services. After some investigation I think I have found that DataSets > leak > memory! > > So I created a simple test > > 1) Create a new Windows Application > 2) Added an Empty DataSet > 3) Put a button on the form and then added this code. > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > While True > For k As Integer = 0 To 100000 > Dim ds As New DataSet1 > ds.Dispose() > ds = Nothing > Next > > GC.Collect() > MsgBox((GC.GetTotalMemory(True) / 1024).ToString()) > End While > End Sub > > The Message box will tell me how much memory wasn't GCed and I get these > results > > 2507K > 4587K > 7168K > ... > > So my question is. Do DataSets leak memory? Or am I doing something > wrong? > > BTW: I see no leak if I am in Release Mode, only in Debug, with or without > the debugger. > > > > This is just a test program I wrote to check that indeed the DataSet is
leaking. If you run it long enought it will crash with an OutOfMemoryException Show quote "W.G. Ryan [MVP]" wrote: > Is this the actual code? How does this loop every stop? Where does True > get flipped to false? > "Gunnar Valur" <GunnarVa***@discussions.microsoft.com> wrote in message > news:2C632526-94D8-4C69-87E0-3E72CF33073A@microsoft.com... > > Hi, > > > > I am using VB 2005 and have been having problems with memory usage in > > services. After some investigation I think I have found that DataSets > > leak > > memory! > > > > So I created a simple test > > > > 1) Create a new Windows Application > > 2) Added an Empty DataSet > > 3) Put a button on the form and then added this code. > > > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > > System.EventArgs) Handles Button1.Click > > While True > > For k As Integer = 0 To 100000 > > Dim ds As New DataSet1 > > ds.Dispose() > > ds = Nothing > > Next > > > > GC.Collect() > > MsgBox((GC.GetTotalMemory(True) / 1024).ToString()) > > End While > > End Sub > > > > The Message box will tell me how much memory wasn't GCed and I get these > > results > > > > 2507K > > 4587K > > 7168K > > ... > > > > So my question is. Do DataSets leak memory? Or am I doing something > > wrong? > > > > BTW: I see no leak if I am in Release Mode, only in Debug, with or without > > the debugger. > > > > > > > > > > > I'm having the same kind of issue. I converted ASP .NET 1.1 app to 2.0,
and for almost all the pages, every time I refresh it, the memory usage goes up and memory doesn't seem to be reclaimed by GC. When I profiled it with Ants Profiler, I saw a significant increase of System.WeakReference which our application never use. Any suggestion as to how we go about resolve this issue? On Jan 8, 11:09 am, Gunnar Valur <GunnarVa***@discussions.microsoft.com> wrote: Show quote > This is just a test program I wrote to check that indeed the DataSet is > leaking. If you run it long enought it will crash with an > OutOfMemoryException > > > > "W.G. Ryan [MVP]" wrote: > > Is this the actual code? How does this loop every stop? Where does True > > get flipped to false? > > "Gunnar Valur" <GunnarVa***@discussions.microsoft.com> wrote in message > >news:2C632526-94D8-4C69-87E0-3E72CF33073A@microsoft.com... > > > Hi, > > > > I am using VB 2005 and have been having problems with memory usage in > > > services. After some investigation I think I have found that DataSets > > >leak > > > memory! > > > > So I created a simple test > > > > 1) Create a new Windows Application > > > 2) Added an Empty DataSet > > > 3) Put a button on the form and then added this code. > > > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > > > System.EventArgs) Handles Button1.Click > > > While True > > > For k As Integer = 0 To 100000 > > > Dim ds As New DataSet1 > > > ds.Dispose() > > > ds = Nothing > > > Next > > > > GC.Collect() > > > MsgBox((GC.GetTotalMemory(True) / 1024).ToString()) > > > End While > > > End Sub > > > > The Message box will tell me how much memory wasn't GCed and I get these > > > results > > > > 2507K > > > 4587K > > > 7168K > > > ... > > > > So my question is. Do DataSetsleakmemory? Or am I doing something > > > wrong? > > > > BTW: I see noleakif I am in Release Mode, only in Debug, with or without > > > the debugger.- Hide quoted text -- Show quoted text - Try to use YourKit .NET profiler http://www.yourkit.com
It will show you paths via GC roots and these WeakReferences, so you can understand how they were created. Regards, Vladimir |
|||||||||||||||||||||||