Skip to main content
SyliusPHPRAM
SyliusPHPRAM Partner Disclosure: Outbound /go/ links marked rel="sponsored" may earn a referral commission at zero extra cost (Partner Disclosure).
Stack Matrix Hub (9)

Preventing Doctrine ORM Hydrator & IdentityMap Memory Leaks

Stop batch product imports, Messenger workers, and FrankenPHP threads from ballooning past 900 MB RSS via IdentityMap clearing and DTO hydration.

EntityManager::clear() / 50 rows · Array/Scalar hydration · 75% less RSS

Preventing Doctrine ORM Hydrator & IdentityMap Memory Leaks
Telemetry verified 2026-11-04 by SymfonyCart Matrix.

How Doctrine IdentityMap Retains Every Hydrated Product & Variant

Doctrine ORM caches every managed Product, ProductVariant, and ChannelPricing entity inside its UnitOfWork IdentityMap until clear() is invoked. Inside long-running FrankenPHP workers or CSV import commands, hydrating 5,000 SKUs with translations inflates a single PHP process past 850 MB.

Read-Only DTOs, Iterable Queries & Periodic UnitOfWork Clears

Use read-only scalar or DTO hydration for catalog feeds and export jobs, stream large queries with toIterable(), and call EntityManagerInterface::clear() every 25 to 50 entities inside Messenger handlers and CLI batch workers.

Measured Thresholds & Configuration

Hydration Pattern (5,000 SKUs)Peak PHP RSSExecution SpeedRecommended Context
Full ORM Object Graph (no clear)880 - 1,150 MBSlow GC pausesAvoid in batch/workers
Batch flush() + clear() every 50165 - 210 MBSteady constant heapCatalog CSV & Messenger imports
Read-Only Scalar / DTO Query64 - 95 MB3.2x fasterAPI feeds, sitemaps & exports
EntityManager::clear() / 50 rows · Array/Scalar hydration · 75% less RSS Launch ChemiCloud ($4.49/mo)UltaHost VDS ($41.50/mo)