I am building contextual tab groups at runtime along with MDI forms. When I am ready to display a new form, I build my tab group and call the RefreshMerge method on my main form. Everything displays properly and works great. However, when I close my child MDI form, I am noticing a memory leak and the child form never disposes completely.
I have tried writing code that disposes each individual tool I add along with any popup galleries, ribbon groups, etc. However, the child form still never disposes completely The ANTS memory profiler tool show objects in the MergedTools Collection. Since I called the RefreshMerge on the main form's toolbarsmanager, I am wondering if there is anything else I need to dispose of. There appears to be a MergedTools collection somewhere. Is there a different method I should be calling to "unmerge" the child MDI form from the main form?
It sounds like you are using the ToolbarsManager correctly. The behavior you describe is unusual, as the tools from the closed form should be released when the form is closed. If it is possible for you to provide a sample application that reproduces the leak, we can look into it over here and try to determine what's causing it. If you would prefer not to upload to the public forum, let me know and I will open a support case to receive the sample.
Please let me know how you choose to proceed.
My project is too big and complex to boil down into a sample app to send to you. Can you give me the "best practice" steps for adding and then cleaning up contextual tabs? I'm currently walking through all the ribbon tabs, groups and collections and manually disposing of each item I added, but this is tedious and I might be missing something. Is there a better way to do this?
This is intended to be handled by the control. As such, there are no real "best practices" to follow in this case -- it should be taken care of by the UltraToolbarsManager.
Your approach seems correct to me. You can also double check the Tools collection directly on the UltraToolbarsManager to see if any of the tools you added exist there.
One more question. There are two forms and each form has an instance of the UltraToolbarsManager. Does it make a difference which one I add/remove the tools from? When I call the RefreshMerge method, does it put the tools into both instances?
The tools are always merged onto the parent UltraToolbarsManager. Any custom actions that you need to perform should be done on the parent.