Memory Management - Object Disposal Best Practices

0
0

I am attempting to track down a memory leak in my application and have been unsuccessful so far.

The application is relatively simple as far as structure goes even though there are a lot of controls.

My Main Page consists of a Split Container with the Menu on the left and the right is used for adding the actual selected user Control.

Nearly all user controls (right panel) have the same structure, a DataGridView for displaying the information, some buttons and an ImageList for the buttons.  When I load the User Control in the right panel, I store a reference to it on the MainPage so I can dispose of it as I change menu selections.

When I change the menu item, I dispose of the Current Control, clear the Right panel and add the new control (saving the reference).

Visual Studio debugging and memory analysis doesn’t show these objects as being held in memory and I haven’t been able to replicate the issue in debug mode, but in production, the system works perfectly for 7 – 14 days (approximate) then at a point in time, the memory usage goes up to 4 – 6 gb and requires an IIS Reset to clear the memory.

I’m not expecting a resolution to this issue here (the above is just for context) as I know that will come down to my specific code and if I cant resolve it, I am more than happy to pay for a support package for further analysis.

What I am hoping for is confirmation that some of the design principles we use (coming from a Win Forms background) are valid in WiseJ applications.

Item 1 – Main Page Reference

The User Controls that reside in the Right Hand panel need to be able to reference the Main Page instance, so we pass in a reference to the Main Page in the User Controls Constructor
public UsersControl(MainPage mainPage) {

          InitializeComponent();

          m_mainPage = mainPage;

}

Is this the preferred method in WiseJ?  Or should Session Variables be used?

Item 2 – Static Database Methods

We make extensive use of Static Database Methods which return DTO objects from the database

public class UserExtensions {

       public static UserListResponse GetAllUsers(…) {

                var response = new UserListResponse();

                //Processing Here

               return (response);  

     }

}

We store the result of these queries as Member Variables of the User Control but when we dispose of the User Control (when the menu selection is changed), Visual Studio is showing that these objects (always a List<T> of the returning type) are still active in memory.

Is there additional steps we need to take to dispose of member variables on the User Control?

Thanks in advance,

Brayden.

 

 

  • You must to post comments
0
0
  1. The reference to the main page is fine. no need to use session variables.
  2. Wisej uses the normal object reference functionality of .NET. You say that you dispose of the User Control, but keep in mind that disposing and garbage collection are different things. The only way a reference to an object is kept in memory in .NET is through a “root” (see MSDN docs). The memory tool in VS shows the path to a root which shows where in the application a reference is being held. Usually is a static somewhere in the app.

If you want to purchase consulting hours, you can contact sales (sales AT wisej.com) or use https://wisej.com/professional-services-request/

Hope this helps!

-Julie

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.