Memory problems with multiple rich text editors with spelling enabled

4 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
    1415 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. UI for WinForms is Visual Studio 2017 Ready
  4. 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.
  5. Dimitar
    Admin
    Dimitar avatar
    1415 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.

     
Back to Top