question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I’m sure an example can be simplified, but somewhere between 0.0.7 and 0.0.10 memory leak were introduced.

import React from "react";
import { RecoilRoot, useSetRecoilState, atom, useRecoilValue } from "recoil";

const state = atom({
  key: "test",
  default: []
});

const Subscriber = () => {
  const setTest = useSetRecoilState(state);

  React.useEffect(() => {
    const u = old => {
      const item = Math.random();

      if (old.length >= 5000) {
        return [item, ...old.slice(0, -1)];
      } else {
        return [item, ...old];
      }
    };

    const t = () => setTest(u);
    setInterval(t, 10);
  }, []);

  return null;
};

const Test = () => {
  const test = useRecoilValue(state);
  return <div>{test.length}</div>;
};

export default function App() {
  console.log("render");
  return (
    <RecoilRoot>
      <Subscriber />
      <Test />
    </RecoilRoot>
  );
}

Codesandbox:
0.0.10: code, demo
0.0.7: code, demo

Sandbox with 0.0.7 version doesn’t have memory leak, as you might see here (app run about 2 minutes between heap snapshots). 0.0.10: image 0.0.7:
image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

10reactions
drarmstrcommented, Jul 28, 2020

We’re finalizing some changes for Concurrent Mode now, then can try to investigate this before the next release.

5reactions
drarmstrcommented, Aug 17, 2020

@saltycrane - Thank you for the reproducer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Memory leak - Wikipedia
In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in...
Read more >
What is Memory Leak? How can we avoid? - GeeksforGeeks
Memory leak occurs when programmers create a memory in heap and forget to delete it. The consequences of memory leak is that it...
Read more >
Definition of memory leak - PCMag
When memory is allocated, but not deallocated, a memory leak occurs (the memory has leaked out of the computer). If too many memory...
Read more >
Memory leak - OWASP Foundation
A memory leak is an unintentional form of memory consumption whereby the developer fails to free an allocated block of memory when no...
Read more >
Find a memory leak - Windows drivers - Microsoft Learn
A memory leak occurs when a process allocates memory from the paged or nonpaged pools, but doesn't free the memory.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found