How to release memory when RadDock is created on PageViewPage?

6 posts, 0 answers
  1. Ralf
    Ralf avatar
    4 posts
    Member since:
    Jun 2008

    Posted 28 Aug 2010 Link to this post

    Hello Team Telerik,

    This is very likely a simple question to answer:

    My test winforms application (Telerik Winforms components Q2 2010) has one RadPageView component on Form1. Each Button1 click will create a new PageViewPage and put a RadDock on it (see code below). Running this app from within VS2008 will show in Windows Taskmanager (Windows 7 32 bit) after the application-start approx. 40MB memory working set. Clicking 20 times on Button1 will increase the memory to approx 80MB. Closing all pages by clicking on the X button of the PageView TabStrip will not reduce the amount of used memory (instead creating another set of 20 pages by clicking Button1 will result in further increased memory allocation). 

    namespace WindowsFormsApplication4
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
     
            private void button1_Click(object sender, EventArgs e)
            {
                RadPageViewPage page = new RadPageViewPage();
                page.Text = "Page";
     
                RadDock dock1 = new Telerik.WinControls.UI.Docking.RadDock();
                dock1.Dock = System.Windows.Forms.DockStyle.Fill;
     
                page.Controls.Add(dock1);
     
                this.radPageView1.Pages.Add(page);
                this.radPageView1.SelectedPage = page;
            }
        }
    }

    Trying to  remove dock1 from the page and disposing it when the page is removed did not help:
    private void radPageView1_PageRemoving(object sender, RadPageViewCancelEventArgs e)
            {
                RadDock dock1;
                RadPageViewPage page = this.radPageView1.SelectedPage;
                if (page != null)
                {
                    Control[] pagecontrols = page.Controls.Find("radDock1", false);
                    int numerofpagecontrols = pagecontrols.Length;
                    if (numerofpagecontrols == 1)
                    {
                        dock1 = (RadDock)pagecontrols[0];
                        page.Controls.Remove(dock1);
                        dock1.Dispose();
                    }
                }
            }

    Thank you very much for any feedback.
    Regards,
    Ralf
  2. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 02 Sep 2010 Link to this post

    Hi Ralf,

    Thank you for the question.

    I tested your scenario using the provided code snippet. I noticed that numerofpagecontrols will never be equal to one, because the Name of the RadDock instances is not set to 'radDock1'. If I set the Name of the dock instances to 'radDock1', the code which disposes the RadDock instances is executed.

    Please note, however, that when you call the Dispose on a RadDock instance, the allocated resources related to this instance are not freed immediately. RadDock has a deep graph of instances, which results in a longer lifetime for some of the internal instances. However, sooner or later, after several GC.Collect() passes the appropriate instances are disposed correctly. You can check this by calling the GC.Collect() explicitly.

    Still, we found an issue with the pages of RadPageView which are not disposed when they are closed. We will address this issue in one of our next releases.

    I am attaching a sample project which demonstrates that the RadDock resources are freed correctly. Just open 20 pages with RadDock, then close them and finally click the GC.Collect button several times. You will notice that the memory consumption will be decreased. Some memory will stay allocated, because of the static resources related to the theming mechanism of RadControls.

    Your Telerik points have been updated for your feedback. If you have additional questions, feel free to contact me.

    Kind regards,
    Nikolay
    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. UI for WinForms is Visual Studio 2017 Ready
  4. Ralf
    Ralf avatar
    4 posts
    Member since:
    Jun 2008

    Posted 02 Sep 2010 Link to this post

    Thank you Nikolay,

    For this answer and for working around the issue in my test code. If I am using your example code the application is starting with 37MB memory, after clicking button "Press me" once, then closing the pages (by clicking on the "X" button in the tab strip) and then clicking on "GC.Collect" the app is using 58MB; doing this round ("Press me"->closing tabs-"GC.Collect") once again will result in 76MB and doing it once again will bring the allocated working memory to approx 110MB.

    Fixing this memory leak in your page closing code will be a pre-condition to decide for Telerik components in my project (a typical user session will include opening and closing of 100 pages during a 2h work session; the app will usually not be closed during a working day but stay open). Is there anything I can do to speed up the process of getting this bug fixed from your dev-team (I looked into PITS http://www.telerik.com/support/pits.aspx#/public/winforms/2010-q2-sp+ but could not find an item relating to this)?

    If a bug fix release would take longer than 4 weeks; would it make sense to use instead of the new PageView (that has this issue) the outdated obsolete Tabstrip?

    Thank you again for any feedback.

    Kind regards,
    Ralf
  5. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 03 Sep 2010 Link to this post

    Hi Ralf,

    Thank you for the question.

    You can find the PITS issue here. As it was not scheduled for fixing in a specific version, it was in the Not Scheduled section. However, we understand the importance of the issue, so I increased its priority in our To-Do list. Therefore, you can now find it in the Q2 2010 SP+ section. We are very close to the release date of Q2 2010 SP2 (in the middle of September) so I cannot guarantee that we will be able to address the issue for this version. However, we hope that we will have the time to do so.

    Sincerely yours,
    Nikolay
    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. Ralf
    Ralf avatar
    4 posts
    Member since:
    Jun 2008

    Posted 03 Sep 2010 Link to this post

    Hello Nikolay,

    Thank you again. The service you provided so far in this case is appreciated and will be a plus for your company in our evaluation of alternatives. If you can get this fixed in Q2 2010 SP2 we will buy your components.

    Regards,
    Ralf
  7. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 09 Sep 2010 Link to this post

    Hi Ralf,

    We thoroughly investigated RadDock and RadPageView, but we did not found any memory leaks in these products. What causes the strange behavior is the fact that you are disposing RadDock on PageRemoving which breaks the standard dispose mechanisms. That said, it is not correct and recommended to dispose the controls on this event and this actually comes from the standard .NET mechanisms.

    In regards to RadPageView, after some discussions with my colleagues, it turned out that the pages are not disposed on purpose. This may come in handy in the cases where you want to use a closed page at a later moment. If you want to dispose a page, you can simply call its Dispose method in the PageRemoved event. This will dispose the contained RadDock instances as well.

    Please find attached a sample project which demonstrates the correct behavior. No matter how many times you press the "Press me!" button, when you close the opened pages and then you call the GC.Collect() several times, you will notice that the allocated memory is about 15 MB more than the initial memory allocated by the application. As I mentioned in my previous response, this allocation is normal and it is due to the static resources taken by the themes.

    I hope information clarifies the situation. If you have additional questions, feel free to contact me.

    Best wishes,
    Nikolay
    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
UI for WinForms is Visual Studio 2017 Ready