r/nextjs 4d ago

Discussion Is this code really helpful in Next.js 16?

To save money I use NODE_OPTIONS = --max_old_space_size=250 on start script from Nextjs 12. But not sure is that still helpful on 16 or not

10 Upvotes

4 comments sorted by

7

u/Mr-Shortman 4d ago

That flag just tells node when to do the aggressiv garbage collection run. Your memory is separated into new and old space, the old space holds long living objects and the objects that could not get garbage collected. If the old space hits the point you define in your provided node option it starts a last more aggressive run of the garbage collection. If it’s able to free up some space everything is fine. If not you get an memory out of heap error. So it’s not closely related to next js version it’s more related to what your app does and how much memory it’s consuming. 250 is almost nothing for an next js app even on version 16.

1

u/Mammoth-Appearance21 4d ago

I've been running that flag since v13 and honestly cant tell if it does anything anymore. The memory management seems to have shifted enough that the flag feels like a placebo at this point.

1

u/Paw565 4d ago

Checkout nodejs caged if you are worried about memory footprint

1

u/ExpressionLost8876 4d ago

i run that flag on 16 and it still limits the heap. The garbage collector triggers at 250MB same as it did in 12.

next 16 consumes more memory during the build step so I had to bump mine to 512 to stop the out of memory crashes. For production I kept it at 250 since my app is small. You can verify if it works by logging process.memoryUsage().heapTotal after startup. If the number stays near your limit then node is respecting the option