PouchDB 抛出 "possible EventEmitter memory leak detected" 个警告

PouchDB throwing "possible EventEmitter memory leak detected" warnings

我在使用 PouchDB 构建应用程序时遇到了这个错误。我刚刚开始使用 Pouch,社区一直在帮助我更好地理解和回答我的问题。

应用程序从 PouchDB 加载文档,然后定期保存它。在大约 6 或 7 次保存后,我在控制台中收到以下错误。

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. 
Use emitter.setMaxListeners() to increase limit.

console.trace()
  87.EventEmitter.addListener @ pouchdb.js:11140setUpEventEmitter @ pouchdb.js:
  1044781.PouchDB.defaults @ pouchdb.js:
  10583(anonymous function) @ eval.js:10
  1../postmessagerpc.js @ eval.js:52
  s @ eval.js:1e @ eval.js:1
  (anonymous function) @ eval.js:1

现在,看看 http://pouchdb.com/errors.html#event_emitter_limit 我看到以下标注:

This could indicate a memory leak in your code. Check to make sure that you are calling cancel() on any changes(), replicate(), or sync() handlers, if you are constantly starting and stopping those events.

我正在使用我的服务中的以下代码检索记录:

obj.get = function (uuid) {
  return localDB.get(uuid).then(function (response) {
    //$log.info(response);
    return response;
  });
};

然后当单击按钮时,我在服务中使用以下方法保存文档:

obj.save = function (doc) {
  return localDB.put(doc).then(function (response) {
    return response;
  }).catch(function (err) {
    $log.error(err);
    return false;
  });
};

我对此没有足够的了解,无法准确说明它发生的原因。根据文档,我认为这只会出现在 .on()'.changes().sync().replicate() 上。

我可能有内存泄漏吗?为什么保存文档会导致发射器?

您是否多次致电 PouchDB.defaults()?这就是调用 setUpEventEmitter() 行的地方:https://github.com/pouchdb/pouchdb/blob/f7280a792ff73a76cd7145166326dd0feb0bde78/lib/setup.js#L126

如果您使用的是 "pouchDB inspector" chrome 插件,则可能是导致此问题的原因。我刚刚在描述它的存储库上打开了一个问题。它似乎并不是真正的内存泄漏。

https://github.com/pouchdb/pouchdb-fauxton-chrome-extension/issues/12