Skip to content

Commit

Permalink
fix(ui): IPC API memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Apr 26, 2018
1 parent d5a3b1f commit 0a3686e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/@vue/cli-ui/src/graphql-api/api/PluginApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PluginApi {
this.clientAddons = []
this.views = []
this.actions = new Map()
this.ipcHandlers = []
}

/**
Expand Down Expand Up @@ -194,6 +195,7 @@ class PluginApi {
* @param {function} cb Callback with 'data' param
*/
ipcOn (cb) {
this.ipcHandlers.push(cb)
return ipc.on(cb)
}

Expand All @@ -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)
}

Expand Down
2 changes: 2 additions & 0 deletions packages/@vue/cli-ui/src/graphql-api/connectors/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0a3686e

Please sign in to comment.