Are hidden BrowserWindow eventually destroyed?


#1

On macOS, instead of closing (and destroying) the main window, I hide it so that it shows instantly when clicking the icon from the dock.

win.on('close', (e) => {
  if (process.platform == 'darwin') {
    e.preventDefault()
    win.hide()
  }
})

win.on('closed', () => {
  win = null
})

app.on('activate', () => {
  if (win) {
    win.restore()
    return
  }

  createWindow()
})

But I’ve received a bug report saying that on win.restore() a Object has been destroyed message popped up. It had been a while since the window was “hidden”.

Any chance hidden windows are eventually destroyed and/or garbage collected?


#2

Make sure you keep the win referenced in your main process, otherwise it will be GC afterward.