Skip to content

Memory Leak When Using waitFor #881

Open
@nathanforce

Description

@nathanforce
  • @testing-library/dom version: 7.29.4
  • Testing Framework and version: N/A
  • DOM Environment: 16.4.0

I've spent the last few days trying to debug what is going on here but I'm afraid I've reached the limit of my knowledge of Node and JS. It seems that there is some sort of memory leak related to the usage of MutationObserver in waitFor.

I've created a bare bones reproduction of the issue in this repo.

The hope is that each test in this bare bones reproduction could be entirely standalone from the others. The basic structure behind the test is as follows:

  1. Create a JSDOM instance
  2. Load a React app bundle in the JSDOM instance
  3. Use @testing-library/dom to assert against that DOM

In the repro you can see that we have the same test repeated 5 times. The log output from running npm test indicates about ~15mb of leaked memory in each test. I suspect this value is the actual JSDOM instance but I am unable to determine what is holding onto the reference.

image

The reason I think it may be related to MutationObserver is that if I comment this line (and any references to observer) then the leaking stops.

I'm really at a loss here so hoping somebody with more familiarity with this sort of thing can shine some light on the issue. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions