Out of Memory Exception (2013.1.220.40)

5 posts, 0 answers
  1. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 27 Feb 2014 Link to this post

    Good afternoon,

    From time to time I've been experiencing Out of Memory Exception with RadRichText box library version 2013.1.222.40.

    My exception is usually thrown when I right click to open the document Context Menu.

    I would like to point out that I do add custom items to the document Context Menu depending if the user right clicks in a section with Custom Annotations.

    e.g.

    private void ContextMenuSubscribe()
    {
        this.radRichTextBox.ContextMenu = new Telerik.Windows.Controls.RichTextBoxUI.ContextMenu();
        ContextMenu contextMenu = (ContextMenu)this.radRichTextBox.ContextMenu;
        contextMenu.Showing += this.ContextMenu_Showing;
    }

    private void ContextMenu_Showing(object sender, ContextMenuEventArgs e)
    {
        #region Discontinue Product Menu Item
     
        // First check the context - if last selected annotation is product and user permissions
        if (Properties.Settings.Default.SystemUserPermissions.ProductsCanDiscontinue == true && !(this.radRichTextBox.Document.Selection.IsEmpty)
            && RadDocumentExtensions.GetLastSelectedAnnotationMarker(this.radRichTextBox.Document) is SemanticRangeStart)
        {
            //Get the selected annotations
            List<SemanticRangeStart> products = RadDocumentExtensions.GetSelectedAnnotationsRangeStarts<SemanticRangeStart>(this.radRichTextBox.Document);
     
            //Check Product Count is greater than 0
            if (products != null && products.Count > 0)
            {
                //Add menu item to data context
                RadMenuItem discontinueProductMenuItem = new RadMenuItem()
                {
                    Header = "Discontinue Product",
                    Icon = new System.Windows.Controls.Image() { Source = new BitmapImage(new Uri("Icons/Spec-Editor-Menu/block.png", UriKind.Relative)) },
                    Tag = products[products.Count - 1] //Get last product item in selection
                };
                discontinueProductMenuItem.Click += this.DiscontinueProductMenuItem_Click;
                ContextMenuGroup customContextMenuGroup = new ContextMenuGroup();
                customContextMenuGroup.Add(discontinueProductMenuItem);
                e.ContextMenuGroupCollection.Add(customContextMenuGroup);
            }
        }
     
        #endregion
     
        #region Product Pricing Menu Item
     
        // First check the context - if selected annotation is end product and user permissions
        if (Properties.Settings.Default.SystemUserPermissions.OrderCanEdit == true && !(this.radRichTextBox.Document.Selection.IsEmpty) &&
            RadDocumentExtensions.GetLastSelectedAnnotationMarker(this.radRichTextBox.Document) is SemanticRangeStart)
        {
            //Get the selected annotations
            List<SemanticRangeStart> products = RadDocumentExtensions.GetSelectedAnnotationsRangeStarts<SemanticRangeStart>(this.radRichTextBox.Document);
     
            //Checked the last selected item is an end item
            //if (products.Count >= 0 && products[products.Count - 1].Product.HasChild == false)
            //{
                //Add menu item to data context
                RadMenuItem addPriceMenuItem = new RadMenuItem()
                {
                    Header = "Set Price",
                    Icon = new System.Windows.Controls.Image() { Source = new BitmapImage(new Uri("Icons/Spec-Editor-Menu/sterling_pound_currency_50.png", UriKind.Relative)) },
                    Tag = products[products.Count - 1]
                };
                addPriceMenuItem.Click += this.SetPriceMenuItem_Click;
                ContextMenuGroup customContextMenuGroup = new ContextMenuGroup();
                customContextMenuGroup.Add(addPriceMenuItem);
                e.ContextMenuGroupCollection.Add(customContextMenuGroup);
            //}
        }
     
        #endregion
     
        #region Add New Item To Database Menu Item
     
        //Check Conditions
        if (Properties.Settings.Default.SystemUserPermissions.ProductsCanAdd == true &&
            this.radRichTextBox.Document.Selection.IsEmpty && RadDocumentAutoComplete.IsPositionBetweenDefinedAnnotations(this.radRichTextBox.Document.CaretPosition) == false)
        {
            //Check if text exists at caret position
            string text = RadDocumentExtensions.GetSpanBoxText(this.radRichTextBox.Document.CaretPosition);
     
            if (!String.IsNullOrWhiteSpace(text))
            {
                text.Trim();
     
                //Create New Menu Item
                RadMenuItem addNewItemToDatabase = new RadMenuItem()
                {
                    Header = "Add New Item",
                    Icon = new System.Windows.Controls.Image() { Source = new BitmapImage(new Uri("Icons/Spec-Editor-Menu/Database-Add-48.png", UriKind.Relative)) }
                };
     
                addNewItemToDatabase.Click += this.AddNewItemToDatabaseMenuItem_Click;
                ContextMenuGroup customContextMenuGroup = new ContextMenuGroup();
                customContextMenuGroup.Add(addNewItemToDatabase);
                e.ContextMenuGroupCollection.Add(customContextMenuGroup);
            }
        }
     
        #endregion
    }


    My application has also been designed to host multiple instance RadRichTextBox in RadDocking Panes (see the attached image). The docking panes are created and closed on a regular basis throughout the lifetime of the applications runtime.

    Another point to add is that my RadDocuments contain a lot of Custom Annotations (unfortunately I cannot upload an example to this forum due to the filters for you to see).

    To iterate my previous points, the Out of Memory Exception thus far only seems to occur once my application has been running for some time and only seems to occur when opening the Context Menu between custom annotations.

    Is the Out of Memory Exception a known issue with library version 2013.1.222.40?
    And can you offer any advice on what may be causing it and how to prevent the exception?

    Many thanks,

    Rob



     
  2. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 27 Feb 2014 in reply to Robert Link to this post

    I've attached two images to this post that show Windows Task Manager Memory usage before the context menu is open and once it has opened.

    Memory Usage Before Context Menu Open: 2.46GB
    Memory Usage After Context Menu Open:  2.71GB

    That's a big jump in memory for a context menu.

    Many thanks,

    Rob
  3. UI for WPF is Visual Studio 2017 Ready
  4. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 28 Feb 2014 Link to this post

    I've taken a snapshot of my stack trace.

    Essentially I opened a RadRichTextBox instance in a new RadDockingPane, modified the documents a little bit then closed the RadDockingPane.

    Is there anything from the snapshot that looks dangerous? I've only just downloaded stacktrace so I'm not really sure on how to asses it yet.
  5. Petya
    Admin
    Petya avatar
    975 posts

    Posted 04 Mar 2014 Link to this post

    Hello Rob,

    Thank you for contacting us!

    Generally, there is a known memory leak related to the context menu in RadRichTextBox which comes from the control's use of MEF. However, I can see you are creating а separate context menu instance for the RadRichTextBox in your application, so this issue should not be present on your side.

    I tried replicating your setup and as far as I can tell a memory leak is not present. Please note that it is normal for some memory to be allocated the first time the context menu is shown. However, even after showing it multiple times after that I could not reproduce an issue.

    If you believe the behavior of your application is inconsistent we'd appreciate it if you open a support ticket and attach a sample application which we can use to troubleshoot this.

    Let me know if you have further comments or questions.

    Regards,
    Petya
    Telerik
  6. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 05 Mar 2014 in reply to Petya Link to this post

    Thank you Petya.

    I actually suspect the problem was stemming from somewhere else within my application. Likely references that weren't or couldn't be disposed by the Garbage Collector.

    I think when opening the context menu it was temporarily pushing my memory beyond its limits and thus throwing the Out of Memory Exception.

    For now I will monitor my application using your StackTrace software.

    If I come across any more information then I will get back to you.

    Many thanks,

    Rob
Back to Top
UI for WPF is Visual Studio 2017 Ready