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

Memory Leak setInterval #16488

Open
Mortalife opened this issue Jan 18, 2025 · 0 comments
Open

Memory Leak setInterval #16488

Mortalife opened this issue Jan 18, 2025 · 0 comments
Labels
bug Something isn't working memory leak

Comments

@Mortalife
Copy link

What version of Bun is running?

1.1.45+196621f25

What platform is your computer?

Linux 5.15.167.4-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

Describe the bug
I seem to have increasing memory from a setInterval in my code. I've run console.log(require("bun:jsc").heapStats()); And seen that the number of objects keeps increasing and with it the memory.

Managed to distil it down to a simple script.

To Reproduce

This is a simple setInterval, mean to represent doing "work".

// index.ts
setInterval(async () => {
  const time = Date.now();

  if (Date.now() - time > 100) {
    console.log("LAG");
  }

  if (time % 10 === 0) {
    console.log(
      "Memory usage: ",
      Math.trunc(process.memoryUsage.rss() / 1024 / 1024),
      "MB"
    );
  }
}, 100);

Put it in a file and run it with bun run index.ts

What is the expected behavior?

Expected behavior
I expect it not to leak.

What do you see instead?

Current Output
The current output over less than a minute:

Memory usage:  35 MB
Memory usage:  35 MB
Memory usage:  35 MB
Memory usage:  35 MB
Memory usage:  35 MB
Memory usage:  35 MB
Memory usage:  35 MB
Memory usage:  35 MB
Memory usage:  38 MB
Memory usage:  38 MB
Memory usage:  38 MB
Memory usage:  38 MB
Memory usage:  38 MB
Memory usage:  38 MB
Memory usage:  38 MB
Memory usage:  38 MB
Memory usage:  38 MB
Memory usage:  39 MB
Memory usage:  39 MB
Memory usage:  39 MB
Memory usage:  39 MB
Memory usage:  39 MB

Additional information

Additional context
Tried it in node 22, didn't leak.

@Mortalife Mortalife added bug Something isn't working needs triage labels Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working memory leak
Projects
None yet
Development

No branches or pull requests

2 participants