sindresorhus / electron-better-ipc

Simplified IPC communication for Electron apps
MIT License
715 stars 60 forks source link

Properly clean up the event listeners #32

Closed ulken closed 4 years ago

ulken commented 4 years ago

Extracted as unrelated change from #31.

Fix memory leak where listeners are not being properly removed + add accompanying test.

Note about test: I've confirmed that the test for ipcMain failed before fix, but ipcRenderer reported 0 listeners via spectron even though I've confirmed by logging in the implementation that is not the case. Moreover, all the send channel listeners are definitely still registered (as they need to be explicitly removed).

I think spectron is to blame here, but I'm not sure as I'm not deeply familiar with electron altogether. Maybe both can't run in the right context in the same test?

sindresorhus commented 4 years ago

Good catch :)