Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
475
Memory leak when using FormulaEditorDialog
posted

My Window will not be garbage collected if it has a child of type FormulaEditorDialog.

For a simplified example call the following two event handlers on buttons of any dialog.

WeakReference _WeakRef = null;

private void OnCheck(object sender, RoutedEventArgs e)

{

GC.Collect();

GC.WaitForPendingFinalizers();

if(_WeakRef.IsAlive)

{

throw new Exception("Window alive!");

}

}

private void OnDialog(object sender, RoutedEventArgs e)

{

Window dlg = new Window();

dlg.Content = new FormulaEditorDialog(); // with this line dlg lives forever

_WeakRef = new WeakReference(dlg);

if(dlg.ShowDialog() == true)

{

}

}

The window will stay alive, if it has content of type FormulaEditorDialog.

Do you have any workaround or solution for this problem?

TIA

Michael

Parents Reply Children
No Data