I am just starting a new WPF project using MVVM as a general guideline. The application will have a ribbon; when you switch between tabs, there will be different buttons that spawn dockable windows in the content pane below the ribbon. This part is done. Now, each of those windows contains a different user control. These user controls all can interact with data used in the other user controls. There is going to be somewhere between 20 - 30 different user controls. My question: Is it more efficient for me to create one single static instance of these user controls or to generate and destroy each user control as I need it? Using the static controls method, the user controls would always be in memory but there would be considerably less run time code (the interaction code along with the loading of the data; this program is very data intensive). Generating and destroying the controls as needed would no longer keep the controls in memory constantly, but the run time code would be more complex and could possibly cost more in terms of efficiency. Is one method a really bad idea because of X reason that I may have over looked? Are there certain cases where one method is highly efficient over the other? Any guidance on this issue would be greatly appreciated!

1 Year
Discussion Span
Last Post by JOSheaIV

Well you can at least from a time perspective, used the System.Diagnostics.Stopwatchlibrary, and test the time it takes to initally load up everything at once, and what it takes to create them.

How much data are we here? Some strings? Images? 100k+ record?

Another trick is to use your Resource Monitor (click the start menu in windows and type that). You can track the resource usage of an application through that.

Personally, if I knew the tabs would always exist, and always be designed the same. I would place all the design elements ahead of time, and then build them to simply populate and dispose of the data itself (which I could control in the code).

Usually when it's small things like string and stuff, it's not a massive resource hog to leave as is. Now when you start getting into Images and LARGE collections of data, disposing is nice (unless you share the image then you can initialize it once and share the resources across all objects, like a default image). Sorry if that's a ramble, I am developing my own Image Selection form, (since the built in C# one you can't thread well and takes forever to load stuff), and working with images can be resource intensive.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.