nextjs - 💡(How to fix) Fix Memory leak causing OOM still occurs in Next.js 16.0.10 (also tested with 16.0.1) when using output: standalone with fetch requests. #90431 [2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#90432Fetched 2026-04-08 00:20:07
View on GitHub
Comments
2
Participants
3
Timeline
13
Reactions
0
Timeline (top)
mentioned ×4subscribed ×4commented ×2closed ×1
RAW_BUFFERClick to expand / collapse

Can we open this issue back? This still looks unresolved.

@subash-thirumaran Are you using next@canary? Not all changes are on next@latest. Recommend opening a new issue which includes providing a reproduction.

@iMUngHee I was unable to reproduce the cancelling retaining but your research looked plausible so I've merged #88577 with the relevant changes.

@altyntsevlexus unfortunately screenshots are not helpful as it only proves memory is being retained, which can be in the application itself as well. What you can do is collecting a .heapprofile. In order to collect that you can start the server using next start --inspect -> open chrome devtools -> click the Node.js icon on the right -> a separate devtools open that is connect to the server -> go to memory tab -> Allocation on timeline -> record -> reproduce the issue -> stop recording -> save the profile and share it.

Originally posted by @timneutkens in #85914

Link to the code that reproduces this issue https://github.com/vercel/next.js/issues/85914

To Reproduce Create a Next.js app with output: 'standalone' Make fetch requests With just 2 requests per second, OOM occurs after a few minutes Current vs. Expected behavior Current: Memory continuously grows until OOM after ~2 requests/second. GC cannot release the memory. Expected: Memory should stabilize, GC should work properly, no OOM. Provide environment information

  • Platform: Linux
  • Node: v22.16.0
  • Next.js: 16.0.10
  • output: standalone
  • Router: App Router Which area(s) are affected? (Select all that apply) Performance

Which stage(s) are affected? (Select all that apply) Other (Deployed)

Additional context i also use "next": "16.2.0-canary.51", seem didt work

Heap Timeline Analysis The heap timeline shows that string and object types are being retained and continuously accumulated. These objects are referenced by cacheController

nextjs-memory-leak.heaptimeline.zip

extent analysis

Fix Plan

Step 1: Collect Heap Profile

To diagnose the memory leak, we need to collect a heap profile. This can be done by running the server with next start --inspect and following the steps in the comment:

next start --inspect

Open Chrome DevTools, click the Node.js icon, and connect to the server. Go to the Memory tab, select "Allocation on timeline", record, reproduce the issue, stop recording, and save the profile.

Step 2: Analyze Heap Profile

Analyze the collected heap profile to identify the objects and types that are being retained and continuously accumulated. In this case, the heap timeline shows that string and object types are being retained and referenced by cacheController.

Step 3: Fix Memory Leak

Based on the analysis, we need to fix the memory leak in cacheController. This can be done by:

  • Identifying the objects and types that are being retained and continuously accumulated.
  • Implementing a mechanism to release these objects and types when they are no longer needed.
  • Optimizing the cache controller to reduce memory usage.

Step 4: Update Code

Update the cacheController to fix the memory leak. This may involve adding code to release objects and types when they are no longer needed, or optimizing the cache controller to reduce memory usage.

// Before
const cache = {};

// After
const cache = {};
setInterval(() => {
  Object.keys(cache).forEach(key => {
    delete cache[key];
  });
}, 1000 * 60); // Release cache every minute

Step 5: Test and Verify

Test the updated code to verify that the memory leak is fixed. This can be done by running the server and monitoring memory usage over time.

next start --inspect

Open Chrome DevTools and monitor memory usage. If the memory usage stabilizes and does

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING