Reputation: 706
I'm working on somewhat large application that is divided into groups by functionality. Since every functionality is mostly independent (they all use the same database, but there is no direct interaction between different functionalities), I'm using the user defined controls and treating them as individual "applications". The way the application works is this:
The user selects the functionality (by clicking on the appropriate button) he/she wants and the user control that contains the "form" is displayed in the second panel. The code that displays all of the user controls looks like this:
panel2.Controls.Clear();
UserControl1 uc1 = new UserControl1();
uc1.Location = new Point(0, 0);
panel2.Controls.Add(uc1);
label6.Text = "User control 1";
So, when the user selects one of the functionalities, the application clears existing controls, and displays the selected one. The application works fine (the part I implemented so far), so this is my question - how does this approach manage computer resources, mainly the memory. Specifically, if the user uses one functionality, and then switches to another one, will the .NET's services release the memory used by the previous functionality (I think garbage collector is in charge of that) and will the SQL connections, that I use to communicate with the database, be closed? Also, are there some other issues that I should be aware of? As I said, the functionalities work properly, but I'm still very far from full testing of the application as a whole (I only test every functionality individually when I create it, and only on the computer I create it on, so I can't consider it as a proper testing). Because of that, I am worried that the application's performances might deteriorate if the application is constantly used over a longer period of time. I'm using VS 2010 (C#) and SQL Server 2005 to create this application. If you have any suggestions, please write them. With this question, I'm trying to prevent major reconstructions of the application once it comes to the phase of testing and implementing due to bad resource management. Thanks.
Upvotes: 3
Views: 2126
Reputation: 2135
Garbage collector is in charge of freeing up the memory that belongs to objects that are not referenced anywhere. If your Windows Forms' Form shows many controls at once, they are all somehow referenced by the form at the time, so the GC won't clean anything up here, you need to be careful not to load too many objects in these controls. Furthermore, you may run into memory issues if you do not properly Dispose
the controls before calling the panel2.Controls.Clean()
.
Upvotes: 1
Reputation: 879
I'm creating an application like this too. What I experience is a lot of difficultys when it comes to managing the controls (See my question here on stackoverflow)
My expectations are that the memory used by the application can become a lot. You should close controls you do not need anymore to prevent this. Also the connections with SQL, I'd reccomend to open/close them manually, so you can be sure there are no conflicts later.
Upvotes: 0