To find a memory leak
-
Has anyone else suffered a memory leak in their VB.NET programs? I have a few classes that are created when a form is created. The whole thing is quite complex and wasn't written by me. I would expect any class I create to be destroyed when the form is closed, but they all seem to sit around in memory. The garbage collector just seems to shuffle about all the time and not free the memory. Even when I do nothing in the application, the GC reports varying values for the GetTotalMemory() method. My problem is that I can't tell what is referencing the memory that can't be freed. A restart of the application is the only way to clear the memory at the moment. Any advice? I'm getting desparate! :confused:
-
Has anyone else suffered a memory leak in their VB.NET programs? I have a few classes that are created when a form is created. The whole thing is quite complex and wasn't written by me. I would expect any class I create to be destroyed when the form is closed, but they all seem to sit around in memory. The garbage collector just seems to shuffle about all the time and not free the memory. Even when I do nothing in the application, the GC reports varying values for the GetTotalMemory() method. My problem is that I can't tell what is referencing the memory that can't be freed. A restart of the application is the only way to clear the memory at the moment. Any advice? I'm getting desparate! :confused:
Google for '.NET Memory Profiler' or 'Allocation Profiler'. You'll find a bunch of them , some trial version, some shareware. I've used the Allocation Profiler from GotDotNet before with pretty good results, plus, you can get the source for it! RageInTheMachine9532
-
Google for '.NET Memory Profiler' or 'Allocation Profiler'. You'll find a bunch of them , some trial version, some shareware. I've used the Allocation Profiler from GotDotNet before with pretty good results, plus, you can get the source for it! RageInTheMachine9532
I downloaded the trial of SciTech .NET Memory Profiler 2.0 (http://www.scitech.se/memprofiler/Default.htm). This tool helped me find the memory leak. FWIW: When I create an event handler for a multi-line text box, the form sits in memory after being closed. I removed the handlers and the form is removed! I've never seen anything like it. I have NO CODE in the handler, just this: Private Sub TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTextbox1.TextChanged End Sub And if I remove it, my 1K+ form will remove itself from memory. If the handler is in there, no number of GC.collect statements will free the damned thing. Garbage I say GARBAGE !!! Don't worry, nobody lives forever.