The code below will cause external memory leak of v8 engine. In v8, mark-compact updates the external_memory before the gc, which cause the external_memory_limit too big. Normally, It's fine, we just got a bigger limit. But when scavenge happened before next mc, updated the external_memory, the external_memory_limit will keep increasing.
I thought this issue has already been fixed in these commits, and node v9.x already ported them:
https://codereview.chromium.org/2917853004
https://codereview.chromium.org/2921883002
function triggerScavenge() {
let arr = [];
for (let i = 0; i < 5000; i++) {
arr.push({});
}
setTimeout(triggerScavenge, 50);
}
let ds = [];
function triggerMarkCompact() {
const { rss, heapTotal, heapUsed, external } = process.memoryUsage();
console.log('------memoryUsage------', rss, heapTotal, heapUsed, external);
for (let i = 0; i < 1000; i++) {
ds.push(new ArrayBuffer(1024));
}
if (ds.length > 40000) {
ds = [];
}
setTimeout(triggerMarkCompact, 200);
}
triggerScavenge();
triggerMarkCompact();
Run the script with --trace-gc to dump gc info.
Attached a graph of the memory usage

The code below will cause external memory leak of v8 engine. In v8, mark-compact updates the
external_memorybefore the gc, which cause theexternal_memory_limittoo big. Normally, It's fine, we just got a bigger limit. But when scavenge happened before next mc, updated theexternal_memory, theexternal_memory_limitwill keep increasing.I thought this issue has already been fixed in these commits, and node v9.x already ported them:
https://codereview.chromium.org/2917853004
https://codereview.chromium.org/2921883002
Run the script with
--trace-gcto dump gc info.Attached a graph of the memory usage
