Description
This one took me a while to figure out, had to write my own "slim" proxyquire to find it.
Where I work, we use proxyquire to mock our modules and our test suite has around 1050 tests. We ran into issues where mocha --watch
would crash after a couple of runs because the garbage collector was not able to garbage collect anymore.
If I compare successive heap dumps I notice that as time goes by I end up having more and more Module objects.
If you look at the contructor of Module, you'll notice that whenever we load a new module, this one gets pushed as a children of the module's parent.
In my slim proxyquire, the fix for the leak was to simply parent.children.pop()
whenever I call Module._load
and to also remove proxyquire from proxyquire's parent module.children.