Hi Happy,
Usually you should detach the event handlers when you don't need them, because the class that raises the events will keep the reference to the handler until it is disposed, hence the classes/controls that declare/attach the event handlers will live longer. If you do not keep a reference to RadWindow it should properly be disposed, as well as its content. You can test this with the following code, where SilverlightControl2 is just a UserControl with any content:
<Button Content="Show window" Click="Show_Click" />
<Button Content="Check disposed" Click="Check_Click" />
private void Show_Click(object sender, RoutedEventArgs e)
{
RadWindow window = new RadWindow();
window.Closed += window_Closed;
window.Content = new SilverlightControl2();
this.control = new WeakReference(window.Content);
window.Show();
}
void window_Closed(object sender, WindowClosedEventArgs e)
{
RadWindow window = sender as RadWindow;
window.Closed -= window_Closed;
}
private void Check_Click(object sender, RoutedEventArgs e)
{
GC.Collect();
Debug.WriteLine(this.control.IsAlive);
}
Sincerely yours,
Valeri Hristov
the Telerik team