so I'm trying to find a memory leak in an app I've deployed to Heroku. I use express post requests in most if not all of my functions so I think there's some fundamental issue I'm missing here. Looking at the 'Closures' section of this link (https://betterprogramming.pub/the-4-types-of-memory-leaks-in-node-js-and-how-to-avoid-them-with-the-help-of-clinic-js-part-1-3f0c0afda268), it seems like you have to nullify variables to deallocate the memory they take up. Here is my function:
async function HelperFunction() {
const client = await pool.connect()
return new Promise( async (resolve, reject) => {
let var0 = []
let currentDate = new Date()
let date = ("0" + currentDate.getDate()).slice(-2);
let month = ("0" + (currentDate.getMonth() + 1)).slice(-2);
let year = currentDate.getFullYear();
let currentTimestamp = year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds
try {
await client.query('BEGIN')
const res = await client.query(querySQLFunction, [currentTimestamp]);
for (row of res.rows) {
let jsonObject = {
var1: row.var1,
var2 : row.var2,
var3 : Number(row.var3),
var4 : Number(row.var4),
var5 : 0
}
var0.push(jsonObject)
}
await client.query('COMMIT')
} catch(err) {
await client.query('ROLLBACK')
console.log(err)
} finally {
client.release()
resolve(var0)
}
})
}
So for example, in the above function, do I have to set all the lets to null in the 'finally' block? Also, if I define functions inside other functions:
async function otherFunction() {
const foo = async (page) => {
//await query some stuff
}
//nullification of foo here?
}
do I have to set the const's to null before the function is over?