Skip to content

Fix TextBoxLineCountBehavior memory leak#4024

Merged
Keboo merged 1 commit intomasterfrom
issue4003
Mar 25, 2026
Merged

Fix TextBoxLineCountBehavior memory leak#4024
Keboo merged 1 commit intomasterfrom
issue4003

Conversation

@nicolaihenriksen
Copy link
Contributor

@nicolaihenriksen nicolaihenriksen commented Mar 25, 2026

Fixes #4003

This PR fixes (or at least drastically improves) the memory leak mentioned in the issue. Basically, the code was blindly queuing new updates of the attached property on every layout update. When resizing a window or doing something else causing a lot of layout events, this would "congest" the message pump with essentially the same lambda.

This PR introduces a flag _uiUpdateInProgress which is set once an update is being queued, and cleared once an update has finished. If a layout change happens in between, it is simply ignored.

The below shows the memory usage captured in the Visual Studio diagnostics tools before/after the fix. The reproduction step was to open the app (from the linked issue), and repeatedly resize the window.

Memory usage before the fix (continuous growth, insane number of GC calls, no drop-down to "normal" after resizing finishes):
image

Memory usage after the fix (still growth which is expected, much fewer GC calls, and a drop-down to "normal" after resizing finishes):
image

If an update has already been queued for processing (but not yet completed), simply skip queuing another update.
@nicolaihenriksen nicolaihenriksen added this to the 5.3.2 milestone Mar 25, 2026
@nicolaihenriksen nicolaihenriksen requested a review from Keboo March 25, 2026 10:28
@Keboo Keboo merged commit 17ed69e into master Mar 25, 2026
2 checks passed
@Keboo Keboo deleted the issue4003 branch March 25, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextBoxLineBehavior: Causing memory leak when a large number of text boxes with this behavior attached.

2 participants