sindresorhus / import-fresh

Import a module while bypassing the cache
MIT License
284 stars 25 forks source link

Memory leak #2

Closed adammockor closed 7 years ago

adammockor commented 8 years ago

This module creates memory leak. Simple test case scenario is:

const heapdump = require('heapdump');
const requireUncached = require('require-uncached');

let i, m1, m2;

for (i = 0; i < 100000; i++) {
  m1 = require('./module.js');
  m1();
}

heapdump.writeSnapshot('./before-' + Date.now() + '.heapsnapshot');

for (i=0; i < 100000; i++) {
  m2 = requireUncached('./module.js');
  m2();
}

heapdump.writeSnapshot('./after-' + Date.now() + '.heapsnapshot');

More information can be found here https://github.com/nodejs/node/issues/8443.

I can PR this, but I am not sure how to handle this correctly.