Tuesday, 9 September 2025

Resource-Aware Design in WinForms - TextBox versus RichTextBox

The TextBox is the clear winner when it comes to memory usage - as it is optimised for plain text only, versus the RichTextBox which supports rich text formatting as well as images and tables. 

This means the startup cost is also less.  Layout logic is also a source of resource consumption in the latter, as it uses FlowDocument internally for layout, whereas TextBox is just a simple stream of text.

Here are some metrics to compare 1000 instances of TextBox versus 1000 instances of RichTextBox:

Initial memory: 45MB vs 60MB  (33% heavier)
Memory used: 3MB
Control creation time: 120ms vs 250ms

Restoring a mass of text boxes from memory will take half the time if we use a regular TextBox versus a RichTextBox.

No comments:

Post a Comment