Memory problems with multiple rich text editors with spelling enabled

7 posts, 0 answers
  1. Jason
    Jason avatar
    18 posts
    Member since:
    Aug 2014

    Posted 22 Dec 2014 Link to this post

    I have a form with multiple rich text editors, all with custom spell checking.
    I did have this code to set the spell checker:
    System.InvalidOperationExceptionvar culture = CultureInfo.GetCultureInfo("en-AU");
    var checker = (DocumentSpellChecker)radRichTextEditor1.SpellChecker;
    if (!(checker.GetDictionary(culture) is AustralianDictionary))
    {
      checker.AddDictionary(AustralianDictionary.Instance, culture);
    }
    radRichTextEditor1.SpellChecker.SpellCheckingCulture = culture;

    However, I found that I was using hundreds of megabytes of memory.
    The work-around I used was to create a custom document spell checker:
    public class CustomDocumentSpellChecker : DocumentSpellChecker
    {
     
        // Thread-safe thanks to the CLR
        private static readonly CustomDocumentSpellChecker _instance = new CustomDocumentSpellChecker();
     
        private CustomDocumentSpellChecker()
        {
            var culture = CultureInfo.GetCultureInfo("en-AU");
            AddDictionary(AustralianDictionary.Instance, culture);
            SpellCheckingCulture = culture;
        }
     
        public static CustomDocumentSpellChecker Instance
        {
            get
            {
                return _instance;
            }
        }
    }

    I then assigned the custom spell checker to the rich text editor:
    radRichTextEditor1.SpellChecker = CustomDocumentSpellChecker.Instance;

    I'm hoping this approach is reasonable, and that the spell checker won't have a problem with being assigned to multiple rich text editors.
  2. Dimitar
    Admin
    Dimitar avatar
    2155 posts

    Posted 24 Dec 2014 Link to this post

    Hi Jason,

    Thank you for writing back.

    Using a lot of memory does not necessarily mean that there is a memory leak. Before reporting such I would recommend you to test your application with a memory profiler. More information about this can be found here: Things to keep in mind when inspecting your application's memory usage.

    In addition I cannot see any particular reason that you should not use the spell checker with several RadRichtextEditor controls (it appears that one cannot perform a simultaneous spellcheck on two controls). 

    I hope this information helps. 

    Regards,
    Dimitar
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Jason
    Jason avatar
    18 posts
    Member since:
    Aug 2014

    Posted 04 Jan 2015 in reply to Dimitar Link to this post

    Testing with a memory profiler is what led me to the above solution, after our testers reported getting out of memory exceptions.
    It appears that the line:
        var checker = (DocumentSpellChecker)radRichTextEditor1.SpellChecker;
    creates a new DocumentSpellChecker with its own custom dictionary.
    The above work-around ensures that only one custom dictionary is created, and our memory problems are fixed.  This may not be suitable in every situation, but it may help someone.
  4. Dimitar
    Admin
    Dimitar avatar
    2155 posts

    Posted 07 Jan 2015 Link to this post

    Hi Jason,

    Thank you for writing back.

    The specified line does create an new instance of DocumentSpellChecker but only if it is still not created (the first time you are getting it). The code looks like this:  
    get
    {
        if (this.spellChecker == null)
        {
            //other implementation omitted
            this.SpellChecker = new DocumentSpellChecker(customWordDictionary);
        }
     
        return this.spellChecker;
    }

    In your case perhaps you are using many controls and this is why the memory usage is large (this is not a memory leak). Nevertheless your solution is perfectly suitable since you can use the same spell checker with each control.

    If you have any questions, please do not hesitate to contact us.
     
    Regards,
    Dimitar
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. daniel
    daniel avatar
    2 posts
    Member since:
    Nov 2016

    Posted 04 Jan in reply to Dimitar Link to this post

    Hi,

    i made a screen that contain a RadPageView with 7 pages and each page contain 1 RadRichTextEditor.

    Would you advise me to use only 1 RadRichTextEditor because we can see only 1 at a time (I have some solution for that).

    After reading your link "Things to keep in mind when inspecting your application's memory usage." (see above) it s seems it s not, but thank you for advising me.

    I know it's a 4 years old post and i'll be Lucky if i have a response.

     

    Regards,

    Daniel

  6. Dimitar
    Admin
    Dimitar avatar
    2155 posts

    Posted 04 Jan Link to this post

    Hi David,

    I have tested this and there is no big difference in the initial memory usage (with 7 or 0 controls instances). The application can consume more memory if there a lot of loaded documents. But still, there should not be an issue with the memory. Please note that this depends on the user machines as well, and I would advise you to test the regular case on your side. For example, load 7 documents and see what is the memory consumption, if it can cause performance issue on your user machines consider loading one document at a time. 

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  7. daniel
    daniel avatar
    2 posts
    Member since:
    Nov 2016

    Posted 04 Jan in reply to Dimitar Link to this post

    Hi,

    thank you for answer.

Back to Top