Skip to content
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 leak when passed any object to render #818

Open
koshkarov opened this issue Apr 18, 2023 · 1 comment
Open

Memory leak when passed any object to render #818

koshkarov opened this issue Apr 18, 2023 · 1 comment

Comments

@koshkarov
Copy link

koshkarov commented Apr 18, 2023

TEST STEPS:

  1. Create a new folder
  2. Run npm init
  3. Run npm install mustache@4.2.0
  4. Create file index.js
const mustache = require("mustache");

function sleep(ms) {
  return new Promise((resolve) => {
    setTimeout(resolve, ms);
  });
}

async function run() {
  await sleep(15000);
  for (let i = 0; i < 20; i++) {
    for (let j = 0; j < 15000; j++) {
      // test line
      mustache.render(`MemoryLeakMessage: ${i}:${j}`, null);

      // this allows to interrupt the process and collect garbage
      await sleep(0);
    }
    await sleep(5000);
  }
}

void run();
  1. Run code with inspector node --inspect index.js.
  2. Open Chrome Inspector chrome://inspect/
  3. Click on inspect link
  4. Select Memory tab
  5. Click on Take heap snapshot icon once a minute.

ACTUAL RESULT:
The memory heap linearly grows.

EXPECTED RESULT:
The memory heap should not grow.

image

@koshkarov
Copy link
Author

The issue was resolved by setting Mustache.templateCache = undefined;. Not sure what kind of caching mechanism is used, But it seems like it is not adequate. AS with this test the memory consumption can easily go over the memory limits of the application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@koshkarov and others