Skip to content

Is the 'DevTools console' leak valid? #133

@pr0g

Description

@pr0g

Hi there,

I've been playing around with memlab and it seems like an incredibly useful tool, but I'm still finding my way when it comes to understanding what are legitimate leaks, and what may be false positives or issues that can be ignored.

I have an incredibly simple little React demo which implements a list of elements that can be dragged and reordered. I'm using Vite, and I do a vite build and then vite preview before running memlab. My scenario.cjs file starts on a blank page (url()), moves to the page containing the list and presses and releases the first element of the list (action()), and then returns to the blank page (back()). When run, a leak is reported by memlab, it looks as follows:

MemLab found 1 leak(s)
Number of clusters loaded: 0

--Similar leaks in this run: 45--
--Retained size of leaked objects: 7.1KB--
[(GC roots)] (synthetic) @3 [308.1KB]
  --10 (element)--->  [(Global handles)] (synthetic) @23 [25.4KB]
  --75 / DevTools console (internal)--->  [Detached HTMLLIElement] (native) @67311 [7.1KB]
  --8 (element)--->  [Detached HTMLLIElement] (native) @68013 [400 bytes]
  --9 (element)--->  [Detached HTMLLIElement] (native) @68017 [400 bytes]
  --9 (element)--->  [Detached HTMLLIElement] (native) @68021 [400 bytes]
  --9 (element)--->  [Detached HTMLLIElement] (native) @68025 [400 bytes]
  --9 (element)--->  [Detached HTMLLIElement] (native) @68029 [400 bytes]
  --4 (element)--->  [Detached Text] (native) @2962 [80 bytes]

I may be misunderstanding, but it seems DevTools console is acting as a reference to these elements (I imagine to display them for debugging purposes) which is causing them to be reported as a leak. I just want to check if this is accurate, or if the above is more likely a genuine leak, and I'm doing something wrong in my React component.

Below is my scenario.cjs file, and I'm happy to share my rather hopeless React component too if that might be useful to see.

async function dragListItem(page) {
  const listItem = await page.waitForSelector("ul li:first-child");
  const box = await listItem.boundingBox();
  await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
  await page.mouse.down();
  await page.mouse.up();
}

function url() {
  return "http://localhost:4173/blank";
}

async function action(page) {
  await page.click('a[href="/"]');
  await dragListItem(page);
}

async function back(page) {
  await page.click('a[href="/blank"]');
}

module.exports = { action, back, url };

Thanks very much for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions