Memory leak during validation
Memory is leaking during html validation
Reduced test-case
const {HtmlValidate} = require('html-validate');
let ticks = 0;
const tick = () => {
const htmlValidate = new HtmlValidate({});
htmlValidate.validateString(
'<!DOCTYPE html><html><head></head><body></body></html>'
);
ticks++;
};
const report = () => {
const {heapTotal} = process.memoryUsage();
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(`${ticks} ticks done, ${heapTotal} heap used`);
}
console.log('starting...')
setInterval(tick, 0);
setInterval(report, 1000);
Configuration
Any
Expected result
Memory should not leak, especially if new HtmlValidate
instance is created for each validation.
Actual result
↪ node html-validate-test.js
starting...
54433 ticks done, 2149851136 heap used
<--- Last few GCs --->
[752639:0x3827310] 1388059 ms: Scavenge 2044.6 (2050.3) -> 2043.8 (2050.3) MB, 5.6 / 0.0 ms (average mu = 0.333, current mu = 0.482) allocation failure
[752639:0x3827310] 1388133 ms: Scavenge 2044.8 (2050.3) -> 2044.0 (2050.3) MB, 10.8 / 0.0 ms (average mu = 0.333, current mu = 0.482) allocation failure
[752639:0x3827310] 1388208 ms: Scavenge 2044.9 (2050.3) -> 2044.1 (2050.8) MB, 11.2 / 0.0 ms (average mu = 0.333, current mu = 0.482) allocation failure
or faster version
↪ node --max-old-space-size=128 html-validate-test.js
starting...
2632 ticks done, 151437312 heap used
<--- Last few GCs --->
[752162:0x35a73f0] 80061 ms: Scavenge 115.8 (122.2) -> 111.6 (122.2) MB, 1.0 / 0.0 ms (average mu = 0.379, current mu = 0.373) allocation failure
[752162:0x35a73f0] 80077 ms: Scavenge 116.0 (122.2) -> 112.1 (122.2) MB, 1.1 / 0.0 ms (average mu = 0.379, current mu = 0.373) allocation failure
[752162:0x35a73f0] 80092 ms: Scavenge 116.2 (122.2) -> 111.9 (131.9) MB, 1.1 / 0.0 ms (average mu = 0.379, current mu = 0.373) allocation failure
Version
-
node
:12.18.1
-
html-validate
:4.6.0
Edited by Leonid Beschasny