Skip to content
_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN DE
Let's talk

Memory Leak Hunting in Node.js

02. 03. 2025 1 min read intermediate

Node.js žere paměť? Systematický návod jak najít a opravit memory leaky.

Detekce

setInterval(() => console.log(Heap: ${Math.round(process.memoryUsage().heapUsed/1024/1024)} MB), 10000);

Chrome DevTools

node –inspect app.js

Memory Leak Hunting in Node.js

Příčiny

Event listenery

// ❌ emitter.on(‘data’, handler) v loopu
// ✅ emitter.once() nebo removeListener

Closures

Closure drží referenci na velký objekt, který by jinak GC sebral.

Globální cache

// ❌ const cache = {}; cache[key] = data; // roste neomezeně
// ✅ LRUCache s max size

Neuzavřené streamy

Vždy uzavírejte DB connections, file streams, HTTP connections.

LRU Cache

import { LRUCache } from ‘lru-cache’;
const cache = new LRUCache({ max: 500 });

Postup

Heap snapshot → porovnat 3 snapshoty → najít rostoucí objekty → opravit.

node.jsmemorydebugging
Share:

CORE SYSTEMS team

We build core systems and AI agents that keep operations running. 15 years of experience with enterprise IT.