StyleModule memory leak


For JupyterLab 4, we migrated to CM6. And our memory leak tests are showing a minor memory leak from style-mod.js with a style sheet not being recycled.

See for example file editor test (need to expand the details) at JupyterLab Weekly Memory Leak Tests · jupyterlab/benchmarks@76daf5f · GitHub.

Each time we instantiate a new editor, the style sheets are being updated. But in the list of style sheets, there is one style sheet with zero rule that gets inserted at each call instead of being recycle like the other style sheets:

I cannot figure out where that style sheet with no rule is coming from. Would anyone have some suggestions to get to the bottom of it?
I happily propose a PR if you can point me out to the best workaround - I was thinking to skip inserting style sheet with no rules.

I’m not able to reproduce this by creating a bunch of editor views in a loop—when I inspect the resulting StyleSet object I only see non-empty style sheets, a constant amount of them. Could you give a bit more information about what you’re doing?

I found out the memory leak error. One of the style sheet was set dynamically through a Compartment. In case no rules should be added, a theme with zero rule was added instead of setting a empty extension in the compartment.