From 7a04612b0310d36908b96033e50cbeb24dca6c7d Mon Sep 17 00:00:00 2001 From: YouJia Date: Tue, 21 Feb 2017 14:40:47 +0800 Subject: [PATCH] Update nedb_proxy.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复内存泄漏 写法优化 --- node_modules/nedb_proxy.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/node_modules/nedb_proxy.js b/node_modules/nedb_proxy.js index 2733ad57..0050b631 100644 --- a/node_modules/nedb_proxy.js +++ b/node_modules/nedb_proxy.js @@ -24,13 +24,12 @@ function DBProxy(dbname) { this.dbname = dbname; }; -var token = 1; +var token = 0; var token2Callback = {}; DBProxy.prototype.send = function(params, callback, method) { - token++; var m = { - token: token, + token: ++token, method: method, dbname: this.dbname, // 转为json字符串, 如果{[a], [a]}, 在main接收后变成了 {[a], [null]}, 对象引用问题 @@ -84,6 +83,7 @@ DBProxy.prototype.remove = function (params, callback) { ipc.on('db-exec-ret', function(event, m) { var token = m.token; var callback = token2Callback[token]; + delete token2Callback[token]; // console.log('clent 接收到消息'); // console.log(m); // console.log('--------------'); @@ -93,4 +93,4 @@ ipc.on('db-exec-ret', function(event, m) { callback && callback(m.err, m.ret); }); -module.exports = DBProxy; \ No newline at end of file +module.exports = DBProxy;