Skip to content

Proxyquire is leaking on module.parent #174

Open
@charlespwd

Description

@charlespwd

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.

image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions