This is a migrated thread and some comments may be shown as answers.

Does closing RADWindow destroy the object?

5 Answers 421 Views
Window
This is a migrated thread and some comments may be shown as answers.
Ben Hayat
Top achievements
Rank 2
Ben Hayat asked on 27 Feb 2010, 03:38 PM
Let's say I have a button on my MainPage which if you click, it instantiate test.xaml. In Test.xaml, there is a RADWindow, so naturally when user is finished she clicks on close button on the RADWindow. Now, if the user clicks on the button in MainPage, another instance of test.xaml is created with RADWindow. Now, Does the close button of RADWindow destroy these objects? If not, what happens to them, until user ends application?
If I were using SL navigation system and the user would go to another page the Navigation system would destroy the previous page. And I believe, the ChildWindow also kills the object when you click on X or Ok or Cancel.

I want to use RADWindow and then have them start as users click on RADMenu, but I don't lots of object sitting in memory because there is still reference to them. What is the proper way to ensure when user closes a RADWindow, the object is closed too?

Thanks!

5 Answers, 1 is accepted

Sort by
0
Accepted
Miroslav Nedyalkov
Telerik team
answered on 01 Mar 2010, 10:08 AM
Hello Ben,

 The RadWindow doesn't dispose anything when closed - it waits for the GC to clean the momory. As long as you have reference to it the GC will not collect it, so if you want to dispose a RadWindow and its content you should closed the window and clean all your references to it - the GC will do its job and dispose it properly.

Hope this answers your question.

Regards,
Miroslav Nedyalkov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ben Hayat
Top achievements
Rank 2
answered on 01 Mar 2010, 02:45 PM
So, is it suggested that we could use the "Closed" event to dispose the page that is containing the RADWindow?
0
Accepted
Miroslav Nedyalkov
Telerik team
answered on 01 Mar 2010, 04:22 PM
Hello Ben,

 The correct way to use the RadWindow control is to not include it into a page - just create it from the code behind. This way you will not need to do any additional cleanup when the window is closed if you don't have hard references to it.

Sincerely yours,
Miroslav Nedyalkov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
alvin shih
Top achievements
Rank 1
answered on 21 Mar 2010, 05:14 PM
i just downloaded the Q1 2010 version of RadControls and I did some testing using WinDbg.

I created a simple silverlight application which has a button.  When I click the button, I create an instance of the RadWindow and call its Show method to display the window.  I close the window again and ran WinDbg to debug.

I notice that the RadWindow instance is always referenced even though I have closed it.
this is what i'm seeing even though the Window is already closed.  Any thoughts? ( I didn't even set the Content property)

DOMAIN(05CEF2B8):HANDLE(Pinned):26a12f8:Root:  0c6d4250(System.Object[])->
  0b6f551c(System.Collections.Generic.List`1[[System.Object, mscorlib]])->
  0b768b28(System.Object[])->
  0b6ff0d4(Telerik.Windows.Controls.RadWindow)
0
Miroslav Nedyalkov
Telerik team
answered on 23 Mar 2010, 10:54 AM
Hi Alvin,

 I tried this issue out with the following code:

WeakReference referance;
public MainPage()
{
    InitializeComponent();
}
  
private void Button_Click(object sender, RoutedEventArgs e)
{
    var popupwindow = new RadWindow();
    referance = new WeakReference(popupwindow);
    popupwindow.ShowDialog();
}
  
private void Button_Click_1(object sender, RoutedEventArgs e)
{
    GC.Collect();         
    GC.WaitForPendingFinalizers();
    GC.Collect();
  
    MessageBox.Show(referance.IsAlive.ToString());
}

And it seems to work correctly - the first time I click the collect button I receive True, but the second time I receive False - that means that first time the GC didn't needed to collect the RadWindow control, but as it collects it the second time there shouldn't be any references to it.

All the best,
Miroslav Nedyalkov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Window
Asked by
Ben Hayat
Top achievements
Rank 2
Answers by
Miroslav Nedyalkov
Telerik team
Ben Hayat
Top achievements
Rank 2
alvin shih
Top achievements
Rank 1
Share this question
or