Steps to reproduce
Use this simplest plugin, it has a huge array data(abort 40M), doing nothing but adding a ribbon icon:
const { Plugin } = require("obsidian")
module.exports = class Simplest extends Plugin {
big;
async onload() {
this.addRibbonIcon(
"dice",
"Simplest do nothing",
(evt) => {
this.doNothing()
}
)
// this plugin has a lot of data
this.big = Array(10000000).map(_ => "May the world peaceful")
}
async onunload() {
}
doNothing() { }
}
- Open devtools → Memory,jsheap of
obsidian.md
is about 15M - Turn on this plugin,jsheap size raises to ~50M
- Close this plugin,and click garbage collection button on left-top of Memory panel
Expected result
As plugin has been turned off, all memory should be able to clean up,js heap should reduce to ~15M
Actual result
Memory is still ~50M
Environment
- Operating system: win10 21H2
- Obsidian version:1.0.3 / 1.0.3
- Debug info:
Additional information
This memory leak is related to app.workspace.leftRibbon.orderedRibbonActions
。After turning of plugin, there is a registered entry inside this array. An entry contains a callback function , which may contains the this
pointer to plugin.
If assign null
to app.workspace.leftRibbon.orderedRibbonActions
and do garbage collection again, heap size will return to ~15M.