New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory not release after shutdown #1058
Comments
There is no issue with the memory. It's because the garbage collection of Node.js has yet to take place. console.log(new Date(), "init", process.memoryUsage().rss / Math.pow(1024, 2));
let numOfTimes = 5;
const interval = setInterval(function() {
console.log(new Date(), "interval", process.memoryUsage().rss / Math.pow(1024, 2));
if (!--numOfTimes) clearInterval(interval)
}, 30000); I ran the original codes with added const {configure, getLogger, shutdown} = require('log4js');
configure({
appenders: {
everything: { type: 'file', filename: 'all-the-logs.log' }
},
categories: {
default: { appenders: [ 'everything' ], level: 'debug' }
}
});
const logger = getLogger();
let s = [];
for (let i = 0; i < 100; i++) {
s.push("xxxx");
}
let s1 = s.join(",");
setTimeout(()=>{
console.log(new Date(), "after setTimeout", process.memoryUsage().rss / Math.pow(1024, 2));
}, 10000)
for (let j = 0; j < 10; j++) {
for (let i = 0; i < 10000; i++) {
logger.debug(s1 + i);
}
console.log(new Date(), process.memoryUsage().rss / Math.pow(1024, 2));
}
console.log(new Date(), "before shutdown", process.memoryUsage().rss / Math.pow(1024, 2));
shutdown(()=>{
console.log(new Date(), "after shutdown", process.memoryUsage().rss / Math.pow(1024, 2));
}) Output shows the decrease once the garbage collection kicks in:
|
What happens if you undefine logger after your shutdown? Shutdown doesn't seem to destroy the logger, it just resolves pending actions (eg, commit, cleanup your network connections and sync all you appenders) |
It is still dependent on when the garbage collection (GC) kicks in, which is normal and not within log4js. You can try out by changing the following codes (in my previous comment): let logger = getLogger(); // changed const to let shutdown(()=>{
logger = undefined; // newly added
console.log(new Date(), "after shutdown", process.memoryUsage().rss / Math.pow(1024, 2));
}) Depending on when the GC takes place, the output may or may not be similar to mine (in my previous comment). Thus, there doesn't seem to be any memory issue based on this issue report. |
log4js version: 6.3.0
output:
The text was updated successfully, but these errors were encountered: