We take pride in your success. We let our positivity drive us, day in and out. Talk to us at Mindfire to know us more.

Software Technology Tips

In a .net windows application the form might have resource leaks though it is running with managed codes. We can use the below procedure to check if a form is having resource leak.
  1. Open  Windows Task Manager
  2. Click on Process tab.
  3. Select "View" in the menu and then select "Select Columns" menu item.
  4. Check the USER Objects and GDI Objects (check boxes) to make them appear on the process page list header.
  5. The code in your project that lunches the Win Form, please ensure you have called the Dispose method. Forms implement the IDisposable interface so their dispose method must be called the moment they are no longer needed (Test 1). We can call Dispose explicitly or even better to instantiate it implicitly by the help of using clause (Test 2).
  6. We can use the GC.Collect() after the using statement or after the call to dispose for troubleshooting purpose.
  7. Now time to launch the form. Please note the note the USER Objects and GDI Objects values at the task manager. Close the form after some time and when the form is closed, note the values again at the task manager. We can find the value is decreased if it is increased then there is a leak in the form.
  8. Fix the resource leak and  remove the call to GC.Collect(). It is generally unnecessary to make an explicit call to GC.Collect() .
Test 1 :
                              // Test 1:
           // Explicit Calling Dispose
           CheckForm ChkFrm = new CheckForm();
           ChkFrm.ShowDialog();
           ChkFrm.Dispose();  
        
           // Force garbage collection.
            GC.Collect();
 
 
Test 2 :
           // Test 2: 
           // Implicit calling to Dispose
           // Dispose will be called immediately after the using
           // block, when the form goes out of scope.
           using (CheckForm ChkFrm = new CheckForm())
           {
               ChkFrm.ShowDialog();
           }
           
           // Force garbage collection.
           GC.Collect();


Related Tags:

.NET,C#.NET

Author: Naibedya Kar

top

C#.NET

Let us Connect!

privacy

copyright (c) Mindfire Solutions 2007-2012. Login