We have a memory leak issue due to controls being retained by UltraToolbarsManager.
Here is the architecture we have: Control1 has a UltraToolbarsManager. Control1 creates several Control2 objects in tabs. Control2 objects have also UltraGrids. We use the UltraToolbarsManager of Control1 to set the contextMenuUltra's of the UltraGrids of the Control2 objects.
As we close the Control2 objects via tabs, we realize that those Control2 objects are not disposed off the memory entirely, because they are retained by Control1.UltraToolbarsManager.contextMenuUltras.
In order to overcome this issue, we have tried Control1.UltraToolbarsManager.SetContextMenuUltra(UltraGridXYZ, null). However, we realized that even though UltraGridXYZ was disposed, the Control2 object was still retained in the memory, via UltraToolbarsManager.contextMenuUltras.val[]..._target.
Is there a way to detach the Control2 object from the UltraToolbarsManager at the end of its life cycle so that it doesn't remain in the memory? Or shall we maintain a separate UltraToolbarsManager for each Control2 object, that we create?
Hi Burak,
If I am understanding your description correctly, it seems that Control1 is retaining references to the Control2 objects, which prevents the garbage collector from releasing them and their associated controls. You should be able to release the memory by calling Dispose on the Control2 objects once you are done with them.
Please try this out and let me know whether it works.
Thank you for your response, Mike.
Control2.Dispose is already called.
I will try to explain it as simple as I can.
Control1 has a UltraToolbarsManager object.
Control2 has an UltraGrid object and we make the following association:
Control1.UltraToolbarsManager.SetContextMenuUltra(Control2.UltraGrid, "someContextMenuUltra")
At the dispose of Control2, we do the following disassociation:
Control1.UltraToolbarsManager.SetContextMenuUltra(Control2.UltraGrid, null)
Nevertheless, we see in the memory profiler that Control1.UltraToolbarsManager still has a reference to Control2.UltraGrid and therefore, Control2 is retained in the memory.
When a user starts and closes several Control2 objects throughout the day(s), this causes a memory problem in our application.
Is there a way to completely break that reference from Control1.UltraToolbarsManager to Control2.UltraGrid?
In order to investigate this issue, we will need a sample application that reproduces the memory leak. This will allow us to see how the reference is retained and how it should be removed. Please let me know if you would prefer not to upload the sample on the public forum and I will create a private case for you.
If you close the tab in the sample attachment, I expect the UserControl1 object to be disposed from the memory. My memory profiler shows me that this is not the case.
Mike B. asked be to take a look at your sample, and I think there's some confusion here.
You seem to be expecting the closing the Tab will Dispose the controls on that tab. That is not a correct expectation. The Tab control does not, and should not, dispose the controls. You created those controls and you are responsible for disposing them when they are no longer needed. It would be a bad idea for the Tab control to assume that just because the tab was closed that those controls aren't needed any more. You could just as easily want to keep those controls around and re-use them for a new tab or move them somewhere else and the tab control has no way of knowing that.
In fact, not only does the tab control not dispose the controls on the tab, the tab itself is not disposed or even removed from the control. Closing a tab just hides it, it's not removed from the Tabs collection.
If you want the controls to be disposed, then I recommend handling the TabClosed (or TabClosing) event of the UltraTabControl. You could remove the tab itself and also dispose of any controls that are no longer needed inside this event.