Skip to content

[Bug] Font size scaling causes Shiki instances to accumulate indefinitely (memory leak) #79

@kqint

Description

@kqint
  • The Plugin is up to date
  • Obsidian is up to date

Describe the bug
When using Obsidian with the official Quick font size adjustment setting enabled, pressing Ctrl + scrolling the mouse wheel triggers the shiki-highlighter plugin to repeatedly create new Shiki instances without disposing the old ones. The console continuously outputs warnings like [Shiki] xxx instances have been created..., and the instance count keeps growing, severely impacting performance and causing memory leaks.

To Reproduce

  1. Install and enable the shiki-highlighter plugin.
  2. Go to Settings → Appearance → Font section, then enable "Quick font size adjustment".
  3. Open the developer tools (Ctrl+Shift+I) and switch to the Console panel.
  4. Continuously zoom in/out (e.g., hold Ctrl and scroll the mouse wheel 10 steps). The console will show the first warning: [Shiki] 10 instances have been created...; continue scrolling and you will see warnings at 20, 30, etc.

Expected behavior

  • When the configuration changes, the existing Shiki instance should be reused (singleton pattern), or the old instance should be disposed before creating a new one.
  • No warnings about accumulating instances should appear in the console.

Screenshots

Image

Occurs on

  • Windows
  • macOS
  • Linux
  • Android
  • iOS

Plugin version
0.7.4

Additional context
Relevant Logs (excerpt)

app.js:1 Obsidian Developer Console
plugin:shiki-highlighter:33 [Shiki] 10 instances have been created. Shiki is supposed to be used as a singleton, consider refactoring your code to cache your highlighter instance; Or call `highlighter.dispose()` to release unused instances.
Wi @ plugin:shiki-highlighter:33
Gi @ plugin:shiki-highlighter:33
await in Gi
Ki @ plugin:shiki-highlighter:33
i @ plugin:shiki-highlighter:33
loadShiki @ plugin:shiki-highlighter:944
await in loadShiki
load @ plugin:shiki-highlighter:944
await in load
reloadHighlighter @ plugin:shiki-highlighter:945
await in reloadHighlighter
eval @ plugin:shiki-highlighter:945
(匿名) @ app.js:1
(匿名) @ app.js:1
(匿名) @ app.js:1
(匿名) @ app.js:1
e.onConfigChanged @ app.js:1
(匿名) @ app.js:1
(匿名) @ app.js:1
(匿名) @ app.js:1
t.setConfig @ app.js:1
(匿名) @ app.js:1

Note: English is not my native language. This issue description was translated into English with the assistance of AI. Please let me know if anything is unclear or needs further clarification.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions