title: Why does v8 report duplicate module strings in heap in my jest tests?
body: <p>In the process of upgrading node (16.1.x =&gt; 16.5.0), I observed that I'm getting OOM issues from jest. In troubleshooting, I'm periodically taking heap snapshots. I'm regularly seeing entries in &quot;string&quot; for module source (same shallow/retained size). In this example screenshot, you can see that the exact same module (React) is listed 2x. Sometimes, the module string is listed even 4x for any given source module.</p>
  <p>Upon expansion, it says &quot;system / Map&quot;, which suggests to me <em>I think?</em> that theres some v8 wide reference to this module string? That makes sense--maybe. node has a require cache, jest has a module cache, v8 and node i'd assume... share module references? The strings and compiled code buckets do increase regularly, but I expect them to get GC'd. In fact, I can see that many do--expansion of the items show the refs belonging to GC Roots. But I suspect something is holding on to these module references, and I fear it's not at the user level, but at the tooling level. This is somewhat evidenced by observation that only the node.js upgrade induces the OOM failure mode.</p>
  <ul>
  <li>Why would my jest test have multiple instances of the same module (i am using --runInBand, so I don't expect multiple workers)</li>
  <li>What tips would you offer to diagnose further?</li>
  </ul>
  <p>I do show multiple VM Contexts, which I think makes sense--I suppose jest is running some test suites in some sort of isolation.</p>
  <p><a href="https://i.stack.imgur.com/1Gl0x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1Gl0x.png" alt="heap module" /></a></p>
  <p><a href="https://i.stack.imgur.com/654CX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/654CX.png" alt="mutliple contexts" /></a></p>
  <p>I do not have a reproduction--I am looking for discussion, best-know-methods, diagnostic ideas.</p>