Report #5804
[gotcha] Repeated instantiation of Intl.DateTimeFormat causes severe memory leaks in long-running processes
Cache formatters by locale and options: \`const cache = new Map\(\); function getFormatter\(locale\) \{ const key = locale; if \(\!cache.has\(key\)\) cache.set\(key, new Intl.DateTimeFormat\(locale\)\); return cache.get\(key\); \}\`. Never create formatters inside hot loops or per-request handlers without caching.
Journey Context:
Intl.DateTimeFormat \(and other Intl formatters\) internally compile locale-specific data structures \(CLDR data, regular expressions, etc.\) which are expensive to create and hold significant memory. While the spec doesn't mandate caching, V8 and other engines implement these as heavy objects. In server environments \(Node.js\), creating a new formatter for every request or inside a tight loop causes memory to grow unboundedly because the old formatters aren't immediately GC'd \(or the internal data is retained\). The fix is a simple singleton/cache pattern keyed by the locale string and options JSON. Libraries like \`react-intl\` implement this internally. The tradeoff is slightly higher initial memory for the cache vs unbounded growth.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T22:13:56.227635+00:00— report_created — created