I've noticed a memory leak when I add "RestrictInContainer = true" to my XamWebDialogWindows. Disabled, everything gets garbage collected as it should; enabled, though, the control appears to remain subscribed to some SizeChanged events:
0:022> !gcroot 07726064 Note: Roots found on stacks may be false positives. Run "!help gcroot" formore info.Scan Thread 4 OSTHread 17a0Scan Thread 8 OSTHread 188cScan Thread 9 OSTHread 2c8Scan Thread 10 OSTHread 17b0DOMAIN(0CC4B488):HANDLE(Pinned):10712f8:Root: 0823d660(System.Object[])-> 072cbf70(System.Windows.Controls.Grid)-> 07787a18(System.Windows.SizeChangedEventHandler)-> 0773b1f0(System.Object[])-> 07730998(System.Windows.SizeChangedEventHandler)-> 07726064(StaffTrak.Silverlight.SilverlightMessageBox)
I tried setting RestrictInContainer to false before removing the dialog from the containing grid, but that doesn't seem to have any effect.
Can you verify this memory leak?
Hello Jason,
I have tried to reproduce this issue when I add the “RestrictInContainer = true" to XamWebDialogWindow and I couldn’t manage to get any memory issue. Can you give me more details and sample project in order to reproduce this on my side.
Thank you.
Sincerely,DimiDeveloper Support EngineerInfragistics, Inc.
The memory issue I'm noticing is because of the complex visuals we're using in the windows; currently the memory usage increases by 20mb with each window I open, which isn't itself a problem. I think the root of the problem is that XamWebDialogWindow is unable to be garbage collected, so this memory is never released.
I tried to create a sample project utilizing RestrictInContainer, but I was actually never able to GC the windows, regardless of the setting. How is one supposed to manage the lifetime of a XamWebDialogWindow? I add it as a child to a panel somewhere, and remove it from the panel when the window state changes to Hidden. Shouldn't this be enough?
Reusing one window isn't possible because the user may have any number of windows open simultaneously; they must be garbage collected.
Hello Jason, I was tried to reproduce this issue but the memory was down after I closed all of the dialogs. I have test this with VS performance tools, can you tell me how you test this behavior? Please make sure that you are using the latest service release. Also I am recommending you to create new instance in the function you need to show WebDialogWindow in this way the dialog memory will be released after you closed it, otherwise the memory will be released after the parent page is closed and getting disposed.If you still has issue with this, would you mind id you share small sample to investigate it more deeply.I hope this helps.Sincerely,DimiDeveloper Support EngineerInfragistics, Inc.
We noticed the same issue in our application. We got around it by searching for an instance of our window in the Children collection property and calling the Show() method on it to re-use the window rather than create a new one.
private void button1_Click(object sender, RoutedEventArgs e)
{
XamDialogWindow window = null;
// if the window exists don't create a new one
foreach (UIElement elem in grid1.Children)
if (elem.GetType() == typeof(XamDialogWindow))
window = elem as XamDialogWindow;
if (window != null)
window.Show();
}
if (window == null)
// it doesn't exist so create a new one
window = new XamDialogWindow();
window.Content = "MyWindow";
grid1.Children.Add(window);
window.Maximize();
window.RestrictInContainer = true;
Hello,
Thank you for the detailed clarifications. I think that this is a issue and we need to look at it. I have created case (CAS-45490-02YYYW) for you and I will forward this behavior to our development team.
I will contact you in the support case for more information.
I'm using the Silverlight 10.1 Service Release, which appears to be the latest.
I use WinDbg to check whether an object can be garbage collected. I have attached a simple project and will walk through my steps:
If you set "RestrictInContainer = true", then the !gcroot looks like:
DOMAIN(05DD9840):HANDLE(Pinned):23212f8:Root: 07d29260(System.Object[])-> 06d687d8(Infragistics.Silverlight.DialogManager)->
06d68b70(System.Collections.Generic.Dictionary`2[[System.Windows.FrameworkElement, System.Windows],[Infragistics.Silverlight.WeakList`1[[Infragistics.Silverlight.Controls.XamWebDialogWindow, Infragistics.Silverlight.XamWebDialogWindow.v10.1]], Infragistics.Silverlight.v10.1]])->
06d75608(System.Collections.Generic.Dictionary`2+Entry[[System.Windows.FrameworkElement, System.Windows],[Infragistics.Silverlight.WeakList`1[[Infragistics.Silverlight.Controls.XamWebDialogWindow, Infragistics.Silverlight.XamWebDialogWindow.v10.1]], Infragistics.Silverlight.v10.1]][])->
06d64324(System.Windows.Controls.Grid)->
06d823dc(System.Windows.SizeChangedEventHandler)->
06d823c4(System.Object[])->
06d823a4(System.Windows.SizeChangedEventHandler)->
06d79740(Infragistics.Silverlight.Controls.XamWebDialogWindow)
Note the additional SizeChangedEventHandlers that are referenced. This was what caused me to open this thread, but then I noticed that even without RestrictInContainer, the XamWebDialogWindows will never be garbage collected.
Hope this helps to clarify my findings.