Skip to content

External memory leak on node v8.x #21021

Closed
@cirias

Description

@cirias
  • Version: 8.11.2
  • Platform: Linux sirius-Alienware-15-R3 4.13.0-41-generic Tracking / Assuring Compatibility #46~16.04.1-Ubuntu SMP Thu May 3 10:06:43 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

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
memory-leak

Metadata

Metadata

Assignees

Labels

v8 engineIssues and PRs related to the V8 dependency.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions