perf: fix memory leaks in the edge runtime in dev (#57235)
This PR fixes a memory leak when using `next dev` where on HMR, we would always retain the memory associated with the old VM instance, leading to pretty egregious usage of RAM after only a few edits. The leak itself comes from methods like `setTimeout` and `setInterval` capturing the context in which they were called and somehow never releasing, even if the timeout happened, when running in a Node.js `vm`. This is probably a Node.js bug. The fix consists of taking ownership of all timeouts and clearing them ourselves manually at the end of each VM lifecycle. Tested manually: - hello world Next.js app with edge runtime - triggered hmr 10 times - memory usage - base: 400MB - before: 800MB - after: 400MB
Showing
Please
register
or
sign in
to comment