Here is the scenerio:
On application open the user is asked to open a “Project”
Inside a project there are processes, categories, tasks, documents and notes.
There are a few more, but lets keep it simple. Most of the items above are lists that are bound to grids or treeviews.
Each of them have a separate database table and are linked with values in the database.
So after a user opens a project I could do something like this:
- Get Processes that belong to Project ‘A’
- Get Categories that belong to each process
- Get Tasks that belong to each category
- Get Documents that belong to Project ‘A’
- Get Notes that belong to Project ‘A’
and so on
The issue is then if the user closes this Project I have to clear every bound control and clear any variables related, then be ready to open another Project.
So what I am looking for is some advice for the way to handle this type of situation efficiently.
I am using C# .Net, and the application is a Windows Forms application.
Well, any way you slice it, the memory allocations done on load will have to be cleaned up at some point.
Depending on how you do your data access, you may have to do it manually, or .NET’s garbage collector may take care of it for you (most likely).
For this type of application (given the limited requirements you’ve written), I would normally implement it as an MDI application so you could have multiple projects open at once. All of the project loading/disposing code would be run through the child window, so any time a child window is closed, the memory gets cleaned up automatically.
Even if you don’t/can’t do MDI, I would strongly recommend that you follow the dispose-on-unload model instead of keeping the same form open and reinitializing it with new data. The latter model is very prone to erroneous behaviour because of lingering data and/or state (which is programmer error, but is really difficult or even impossible to track down when trying to reproduce a client’s issue). I’ve seen this pattern a lot in WinForms and it isn’t pretty when the form controls and business logic start to get complicated. Dump the form and start again.