Urgent.News

What's breaking now, across thousands of outlets.

Tech

Memory Leaks in JavaScript: Diagnosis, Real Causes, and Correction

Um processo Node.js que reinicia sozinho a cada 40 minutos raramente está com bug de lógica. Está com vazamento de memória. O sintoma clássico: o container roda liso por meia hora, o heap_size_used sobe em degraus, o garbage collector começa a rodar com mais frequência (major GC a cada poucos segundos em vez de a cada poucos minutos), a latência p99 dobra e o orquestrador mata o pod com OOMKilled…

Translated from Portuguese Read in Portuguese

A Node.js process that restarts every 40 minutes is often not caused by a logic bug, but rather a memory leak. The classic symptoms include a steady increase in heap size, more frequent garbage collection, and increased latency, ultimately leading to the process being killed due to excessive memory usage. The V8 JavaScript engine uses a mark-and-sweep approach with reachability from a set of roots to determine garbage, not reference counting.

A memory leak typically occurs when objects are promoted to the old space and never released, and can be diagnosed using tools like `--expose-gc` and heap snapshots. Common causes of memory leaks include listeners that are never removed.

Written by urgent.news from Dev.to's report — not a translation of it. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Friday 11 September →