Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not found leaks! (not as expected) #40

Closed
quyatong opened this issue Oct 5, 2022 · 3 comments
Closed

Can not found leaks! (not as expected) #40

quyatong opened this issue Oct 5, 2022 · 3 comments

Comments

@quyatong
Copy link

quyatong commented Oct 5, 2022

I created a SPA. The code was written below.

import * as React from "react";
import { Routes, Route, Outlet, Link } from "react-router-dom";
window.cache = [];
export default function App() {
  return (
    <div>
      <Routes>
        <Route path="/" element={<Layout />}>
          <Route index element={<Home />} />
          <Route path="about" element={<About />} />
        </Route>
      </Routes>
    </div>
  );
}

function Layout() {
  return (
    <div>
      <nav>
        <ul>
          <li>
            <Link to="/">Home</Link>
          </li>
          <li>
            <Link to="/about">About</Link>
          </li>
        </ul>
      </nav>
      <hr />
      <Outlet />
    </div>
  );
}

function Home() {
  return (
    <div>
      <h2>Home</h2>
    </div>
  );
}

function About() {
  let cache = []
  for(let i = 0; i < 100000; i++) {
    cache.push({index: i});
  } 
  window.cache.push(cache);
  return (
    <div>
      <h2>About</h2>
    </div>
  );
}

scenario file:

function url() {
  return 'http://127.0.0.1:3000/';
}
async function action(page) {
  // puppeteer page API
  await page.click('a[href="/about"]');
}
async function back(page) {
  // puppeteer page API
  await page.click('a[href="/"]');
}
module.exports = {action, back, url};

image

I wonder how to define whether there are leaks, tks for your answer~

@JacksonGL
Copy link
Member

JacksonGL commented Oct 5, 2022

@quyatong By default, {index: i} is not considered as memory leak by MemLab (it could be cache as your example app labeled). MemLab supports self-defined leak detector with the leakFilter callback.

You can start with marking all objects allocated as leak and then refine the leak detector based on your app:

leakFilter(node, snapshot, leakedNodeIds) {
  return true;
}

Note: the callback could also be defined in the scenario file.

@JacksonGL
Copy link
Member

Also check out this doc:
https://facebook.github.io/memlab/docs/guides/guides-find-leaks

@quyatong
Copy link
Author

quyatong commented Oct 5, 2022

Great, thank you very much, I understood more about the MemLab

@quyatong quyatong closed this as completed Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants