I am trying to fill mongoDB database with some random data from faker. So i used setInterval function to run a database Query over and over its working but the problem is when i monitor my memory usage it just growing and growing until it reaches to the that limit of v8 engine no matter how much i increase the limits it crashes anyway just a matter of time.
const faker = require("faker")
let userName;
let email;
setInterval(async () => {
userName = faker.name.findName();
email = faker.internet.email();
await User.create({
userName: userName,
email: email,
})
.then(() => {
//getting memory usage
console.log(process.memoryUsage().heapUsed / 1024 / 1024);
})
.catch(err => {
console.log(err);
});
});
how should i manage memory allocation to stop crashes? is this considered to be a memory leak?