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));
};