Skip to content

Instantly share code, notes, and snippets.

@mercuriete
Created April 26, 2023 11:07
Show Gist options
  • Save mercuriete/302fb34ca5e52591601bd20303419b49 to your computer and use it in GitHub Desktop.
Save mercuriete/302fb34ca5e52591601bd20303419b49 to your computer and use it in GitHub Desktop.
determine what memory limits you have on nodejs
# copied from https://stackoverflow.com/questions/73600496/heroku-node-js-app-allocation-failure-scavenge-might-not-succeed-with-memory-s
const v8 = require('v8');
// added the code below to a route that caused a memory leak
const heapStats = v8.getHeapStatistics();
const heapStatsMB = heapStats;
for (const key in heapStatsMB) {
heapStatsMB[key] = `${(((heapStatsMB[key] / 1024 / 1024) * 100) / 100).toFixed(2)} MB`;
}
console.table(heapStatsMB);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment