facebook / memlab

A framework for finding JavaScript memory leaks and analyzing heap snapshots
https://facebook.github.io/memlab/
MIT License
4.3k stars 116 forks source link

Need guidance on accessing elements in code using heap object ID #99

Closed hdby99 closed 7 months ago

hdby99 commented 7 months ago

Hi,

I'm presently engaged in a project where I'm attempting to pinpoint the specific code element responsible for a memory leak using its Heap object ID . Is there any way of doing this?

Thanks

JacksonGL commented 7 months ago

If you want to mark those objects as memory leaks in E2E tests, consider using the leakFilter callback for self-defined leak detector to pinpoint.

If you have a single heap snapshot and just want to query a node with a specific heap object ID, use the getFullHeapFromFile API:

  const heap = await getFullHeapFromFile(heapFile);

  heap.nodes.forEach(node => {
    if (node.id === 12345) {
      // heap object with ID 12345 found
    }
  });

For more details, please check out the API Docs for traversing heap graphs: https://facebook.github.io/memlab/docs/api/interfaces/core_src.IHeapNode