cheerio js内存泄漏

时间:2016-04-19 16:11:04

标签: javascript memory-leaks cheerio

我正在使用cheerio来解析wikipedia api的结果 我遇到了关于记忆的问题。 这是有问题的代码

for (let response of responses) {
    if (response.statusCode !== 200) {
      throw new Error('Received status: [%s] with message: [%s]', response.statusCode, response.message);
    }
    const $ = cheerio.load(response.body);
    $('table.infobox').find('tr').each(function () {
      const key = $(this).find('th').text().replace(/\u00A0/g, ' ').trim().toLowerCase();
      console.log(key);
    });     
}

经过多次循环后,脚本使用的内存不会被释放。 如果我删除此部分

$('table.infobox').find('tr').each(function () {
  const key = $(this).find('th').text().replace(/\u00A0/g, ' ').trim().toLowerCase();
  console.log(key);
});

一切都很好,内存被取消分配。我使用cheerio错了吗?你看到这段代码中有什么东西会导致内存泄漏吗?

我正在cheerio@0.20.0使用node 5.3.0

0 个答案:

没有答案