Skip to content

fix: prevent memory leak from theme recreation#769

Merged
jaywcjlove merged 1 commit into
uiwjs:masterfrom
zukmkv:fix-memory-leak
Jul 8, 2026
Merged

fix: prevent memory leak from theme recreation#769
jaywcjlove merged 1 commit into
uiwjs:masterfrom
zukmkv:fix-memory-leak

Conversation

@zukmkv

@zukmkv zukmkv commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

There's a memory leak happening every time CodeMirror remounts; it duplicates styles because defaultThemeOption is recreated on every mount. It was fixed by adding a static reference to the extension with the .cm-scroller rule, and caching and reusing the other defaultThemeOption part that sets dimensions. Basically, when reused from the cache with the same widths and heights, we do not recreate the extension.
Below is the example without changes after several remounts:

image

However, there's still a thing that if you implement logic where you change dimensions (let's say only height) programmatically, they will not be replaced in the CSS but CodeMirror will just create an extra overriding class:

image

@zukmkv zukmkv force-pushed the fix-memory-leak branch from 138c612 to 9a5a96a Compare July 8, 2026 15:24
@zukmkv zukmkv force-pushed the fix-memory-leak branch from 9a5a96a to aa78df6 Compare July 8, 2026 15:25
@jaywcjlove jaywcjlove merged commit bc982aa into uiwjs:master Jul 8, 2026
1 check passed
jaywcjlove added a commit that referenced this pull request Jul 8, 2026
github-actions Bot pushed a commit that referenced this pull request Jul 8, 2026
@zukmkv zukmkv deleted the fix-memory-leak branch July 8, 2026 17:41
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.

2 participants