I am using node-crone to schedule my job. But I want to clear memory after every job done. So how would I do that?
I am using node-crone to schedule my job. But I want to clear memory after every job done. So how would I do that?
If you declare variables properly within a cron, function or block scope (for example let), then those variables will only survive as long as that scope is alive (i.e. memory cleared).
For example:
var cron = require('node-cron');
cron.schedule('* * * * *', function(){
// y variable will be local to your function
let y = 2;
});
Then, each time the function will finish running Javascript garbage collection could clean up these variable because they are no longer in use.
But, If you'll declare them otherwise they could be kept as global variables and kept alive even after the function finished.
For example:
var cron = require('node-cron');
cron.schedule('* * * * *', function(){
// y becomes a global variable
y = 2;
});