javascript - Is running out of memory in Node an indication of a memory leak?
问题描述
I've recently been studying some of my previous code and not sure where the memory leak is exactly coming form (if any). I seem to be running out of mem quite a lot and I'm sure there is an easier way around this? I initially thought creating the object every second (checkProducts gets called every second) was the issue however I am referencing the product in cache() so. Thank you.
const checkProducts = async () => {
console.log("Checking for new products");
const proxyF = rProxy()
console.log("PROXY " + proxyF.auth.username)
try {
const response = await axios.get(
"https://www.sizeofficial.fr/campaign/New+In/?facet:new=latest&sort=latest", { proxy });
const $ = cheerio.load(response.data);
$("li").each((i, elm) => {
const title =
$(elm)
.find("a")
.text() + "";
const price = $(elm)
.find(".pri")
.text();
const link = $(elm)
.find(".itemImage")
.attr("href");
const quickBuy = $(elm)
.find(".itemQuickView.quickView.btn.btn-default")
.attr("data-quickview-path");
const image = $(elm)
.find("source")
.attr("data-srcset");
if (title !== "" && price !== "") {
const product = {
title: title.replace(/(\r\n|\n|\r)/gm, "").replace(/\t/g, ""),
price: price,
link: "https://www.sizeofficial.fr" + link,
quickBuy: "https://www.sizeofficial.fr/" + quickBuy,
image: image
};
cache(product);
}
});
} catch (err) {
console.log(err);
}
restocks.map(restock => checkRestock(restock));
};
解决方案
推荐阅读
- c++ - 强制 CMake 将 MSVC 与 Ninja 一起使用
- python - 通过使用熊猫添加计数来制作表格
- java - 我在实现通用二叉搜索树的过程中遇到了麻烦
- php - 如何在目录中创建具有唯一名称的目录
- azure-devops - Azure Devops 中的自定义服务终结点:当另一个字段更改时清除用户和密码字段
- javascript - 是否可以直接从服务人员(ServiceWorkerGlobalScope)读取变量?
- ios - 屏幕iOS范围内的自定义变量 - Matomo SDK IOS
- excel - 有没有办法在 ruby 中保存 xlsm 文件中的单元格更改
- c# - Linq RemoveAll 输出?
- python - 如何在 QTableWidget 中获取 ButtonWidget 的行?