WPF Spellcheck Engine takes up too much memory.
- by Matt H.
Each datatemplate in my WPF ItemsControl contains FIVE custom bindable richtextbox controls.
It is a data-driven app that for authoring multiple-choice questions -- The question and four answer choices must all support:
1) Spell check
2) Rich formatting (otherwise I'd use regular textboxes)
The spell check object in .NET 4 has a Friend constructor that takes a single argument of owner As TextBoxBase This means every richtextbox in the ItemsControl has 5 Spellcheck objects!
This is the problem -- every spell check engine is consuming about 500k memory. So after you favor in the spellcheck, bindings, additional controls in the DataTemplate, etc.. a single multi choice question consumes more than 3MB memory.
Users with 100--200 questions will quickly see the App raise it's memory consumption to 500+ MB. Management is definitely not OK with this.
Is there a way to minimimze this problem? The best suggestion I've heard is to enable/disable spellcheck if the richtextbox is in the ItemsControl's scrollviewer: I haven't gotten an answer to how to go about it: (http://stackoverflow.com/questions/2869012/possible-to-implement-an-isviewportvisible-dependencyproperty-for-an-item-in-an-i)
Any good ideas?