Object has been destroyed when open secondary/child window in electron js
<p>In a main window, when a button is clicked, the second/child window will popped up via an ipc call. 
This works when open the pop window on the first time. If I closed the pop window and reopen it again, I will get this error:</p>

<blockquote>
  <p>Uncaught Exception: Error: Object has been destroyed at Error (native)
  at EventEmitter. (/home/xxxx/electron/fin/main.js:36:21) at emitOne
  (events.js:96:13) at EventEmitter.emit (events.js:188:7) at
  EventEmitter.
  (/home/xxxx/electron/fin/node_modules/electron-prebuilt/dist/resources/electron.asar/browser/api/web-contents.js:156:13)
  at emitTwo (events.js:106:13) at EventEmitter.emit (events.js:191:7)</p>
</blockquote>

<pre><code>#main.js on app ready:
mainWindow = new BrowserWindow({width: 800, height: 600})


  mainWindow.loadURL(`file://${__dirname}/index.html`)


  mainWindow.webContents.openDevTools()


  mainWindow.on('closed', function () {

    mainWindow = null
  })

  let popWindow = new BrowserWindow({parent: mainWindow, width: 450, height: 450, show: false});
  popWindow.loadURL(`file://${__dirname}/app/pop.html`);
  popWindow.webContents.openDevTools();

  ipc.on('toggle-popwindow', function(){
         popWindow.show();    
  });
</code></pre>

<p>And when I add hide() in the 'closed' method:</p>

<pre><code>popWindow.on('closed', function (event) {
popWindow.hide();
});
</code></pre>

<p>I get this:</p>

<pre><code>Uncaught Exception:
Error: Object has been destroyed
</code></pre>

<p>What is the problem?</p>