fix(ui): IPC API memory leak

This commit is contained in:
Guillaume Chau
2018-04-27 01:28:45 +02:00
parent d5a3b1f127
commit 0a3686e380
2 changed files with 6 additions and 0 deletions
@@ -25,6 +25,7 @@ class PluginApi {
this.clientAddons = []
this.views = []
this.actions = new Map()
this.ipcHandlers = []
}
/**
@@ -194,6 +195,7 @@ class PluginApi {
* @param {function} cb Callback with 'data' param
*/
ipcOn (cb) {
this.ipcHandlers.push(cb)
return ipc.on(cb)
}
@@ -203,6 +205,8 @@ class PluginApi {
* @param {any} cb Callback to be removed
*/
ipcOff (cb) {
const index = this.ipcHandlers.indexOf(cb)
if (index !== -1) this.ipcHandlers.splice(index, 1)
ipc.off(cb)
}
@@ -32,6 +32,7 @@ const PluginApi = require('../api/PluginApi')
// Utils
const { getCommand } = require('../utils/command')
const { getBasePath } = require('../utils/serve')
const ipc = require('../utils/ipc')
const PROGRESS_ID = 'plugin-installation'
@@ -83,6 +84,7 @@ function resetPluginApi (context) {
// Clean up
if (pluginApi) {
pluginApi.views.forEach(r => views.remove(r.id, context))
pluginApi.ipcHandlers.forEach(fn => ipc.off(fn))
}
pluginApi = new PluginApi(context)