Does closing RADWindow destroy the object?

6 posts, 2 answers
  1. Ben Hayat
    Ben Hayat avatar
    892 posts
    Member since:
    May 2008

    Posted 27 Feb 2010 Link to this post

    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!
  2. Answer
    Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 01 Mar 2010 Link to this post

    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.
  3. DevCraft banner
  4. Ben Hayat
    Ben Hayat avatar
    892 posts
    Member since:
    May 2008

    Posted 01 Mar 2010 Link to this post

    So, is it suggested that we could use the "Closed" event to dispose the page that is containing the RADWindow?
  5. Answer
    Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 01 Mar 2010 Link to this post

    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.
  6. alvin shih
    alvin shih avatar
    13 posts
    Member since:
    Oct 2009

    Posted 21 Mar 2010 Link to this post

    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)
  7. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 23 Mar 2010 Link to this post

    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.
Back to Top
DevCraft banner