diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 34db4a6ae79a..0acbd4dd770b 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -1150,6 +1150,29 @@ describe('BrowserWindow module', function () { }) w.loadURL('file://' + path.join(fixtures, 'pages', 'window-open.html')) }) + + it('releases memory after popup is closed', (done) => { + w.destroy() + w = new BrowserWindow({ + show: false, + webPreferences: { + preload: preload, + sandbox: true + } + }) + w.loadURL('file://' + path.join(fixtures, 'api', 'sandbox.html?allocate-memory')) + w.webContents.openDevTools({mode: 'detach'}) + ipcMain.once('answer', function (event, {bytesBeforeOpen, bytesAfterOpen, bytesAfterClose}) { + const memoryIncreaseByOpen = bytesAfterOpen - bytesBeforeOpen + const memoryDecreaseByClose = bytesAfterOpen - bytesAfterClose + // decreased memory should be less than increased due to factors we + // can't control, but given the amount of memory allocated in the + // fixture, we can reasonably expect decrease to be at least 70% of + // increase + assert(memoryDecreaseByClose > memoryIncreaseByOpen * 0.7) + done() + }) + }) }) }) diff --git a/spec/fixtures/api/allocate-memory.html b/spec/fixtures/api/allocate-memory.html new file mode 100644 index 000000000000..ce3140ab0cd2 --- /dev/null +++ b/spec/fixtures/api/allocate-memory.html @@ -0,0 +1,11 @@ + + +
+ + + + + diff --git a/spec/fixtures/api/sandbox.html b/spec/fixtures/api/sandbox.html index a74a1d5d600a..f8d7aa7921de 100644 --- a/spec/fixtures/api/sandbox.html +++ b/spec/fixtures/api/sandbox.html @@ -1,5 +1,18 @@