You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Memory leak when opening and closing windows #21586
Opening and closing window should not increase memory
Actual Behavior
Memory will increase for each window even after the window has been destroyed
To Reproduce
const { app, BrowserWindow, BrowserView } = require("electron");
const init = () => {
let browserWindow2 = new BrowserWindow({
show: true,
});
let j = 0;
const interval = setInterval(() => {
j++;
if (j > 10) {
clearInterval(interval);
}
for(let i = 0; i < 20; i++) {
let browserWindow = new BrowserWindow({
show: true,
});
setTimeout(() => {
browserWindow.close();
}, 5000)
}
}, 1000);
};
app.on("ready", () => {
init();
});
The above code snipped should not result in more memory than just opening a single window.
I also tried to call the garbage collector manually and I also tried browserWindow.destroy(). No difference.
Reacted by Nicolas Boutet, popod, Abed Abu-Hijleh, Dong Hyun, Song, RickIniguez, Nikita Timoshnikov, Stephen Bradshaw, gearcoded, Fesya, Max and 6 more
leak still present when instantiating BaseWindow instead of BrowserWindow
not every iteration creates leaks. Sometimes the rss after creating windows is the same as before, or even lower than it was before!
creating 10x as many windows each iteration increases the leaked amount by less than 10x
v8 heap size doesn't increase, so the leak is off-heap.
avg increase per iteration with n=2000, numWindows=1 is 0.004796416 MB. with n=2000, numWindows=0 (no windows created!!), the average increase per iteration is nearly the same, at 0.004251648 MB. at numWindows=10, the value is 3x bigger, at 0.015570944 MB.
i tried replacing 'create windows' with 'wait about as long as it takes to create those windows' to rule out the possibility that it was some idle behavior causing the leak. it doesn't seem to be.
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
Activity
jackple commentedon Jul 16, 2020
Is there any solution?
pushkin- commentedon Dec 10, 2020
Can someone test if this repros in Electron 11?
t57ser commentedon Dec 10, 2020
Still happening in electron 11. Opening a single window results in 40mb used RAM while executing the code i posted results in about double the memory.
VladTabaka commentedon Dec 11, 2020
Same here (versions 9 and 11) is it somehow related to #23578 ?
pushkin- commentedon Dec 11, 2020
@VladTabaka That's more related to BrowserViews and the PR wouldn't be in the older Electron releases that are affected.
nornagon commentedon Dec 16, 2020
Did some experimenting with LSan and this looks like a possible candidate:
not 100% sure about my methodology, but I thought I'd post it here anyway :)
nornagon commentedon Feb 4, 2021
This is an odd one. Here are some results from my experimentation.
experiment code
Results:
BaseWindowinstead ofBrowserWindownornagon commentedon Feb 4, 2021
This is at least one source of leakage:
electron/shell/common/gin_helper/trackable_object.cc
Lines 39 to 40 in 476d864
Every time a window is created, we register a callback to destroy it at shutdown, but we never clear those callbacks.
hovancik commentedon Apr 21, 2021
Still and issue on electron 12. Same on Linux. Not sure about mac.
axetroy commentedon Oct 13, 2021
confirm on windows with Electron 11.x.
But macOS works fine.
nornagon commentedon Mar 10, 2022
I can't repro this on macOS on 18.x. Here's a Fiddle-able version: https://gist.github.com/d4d80f154468ca9159287842e4788cfe
github-actions commentedon Oct 8, 2022
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
pushkin- commentedon Oct 10, 2022
I do see some memory being reclaimed on Windows 10 Electron 21, but maybe not all of it? Would be good to get some eyes on this.
44 remaining items
electron-issue-triage commentedon Dec 23, 2025
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
gpetrov commentedon Dec 23, 2025
Bump
electron-issue-triage commentedon Mar 24, 2026
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
gpetrov commentedon Mar 24, 2026
Bump
electron-issue-triage commentedon Jun 23, 2026
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
pushkin- commentedon Jun 23, 2026
Bump
electron-issue-triage commentedon Sep 23, 2026
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!