electron: Memory leak when opening and closing windows

Issue Details

  • Electron Version:
    • 5, 6, 7, 8
  • Operating System:
    • Windows 10
  • Last Known Working Electron version:
    • ?

Expected Behavior

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.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 14
  • Comments: 26 (10 by maintainers)

Most upvoted comments

Bump

Still and issue on electron 12. Same on Linux. Not sure about mac.

This is at least one source of leakage:

https://github.com/electron/electron/blob/476d86491b743c634b07e054cc17e6baf6e9cea4/shell/common/gin_helper/trackable_object.cc#L39-L40

Every time a window is created, we register a callback to destroy it at shutdown, but we never clear those callbacks.

bump

Bump

Bump

bump

bump

Bump