mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Batch Processing using toIterable() #6598
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @stlrnz on GitHub (Jan 5, 2021).
Hi all!
I've updated my application to Doctrine ORM 2.8 some days ago.
Before that, my Repository code to iterate through a large result set looked like the following and worked perfectly even on >500.000 rows without leaking any memory.
Since
Query::iterate()is deprecated now, I tried to useQuery::toIterable()as suggested.With this implementation I stumbled over a massive memory leak in my application. I debugged this and found out that the
AbstractHydratoris never releasing the Objects inAbstractHydrator::toIterable(). The called methodAbstractHydrator::hydrateRowData()(or in my caseSimpleObjectHydrator::hydrateRowData) just adds new entries to$result.378944dd27/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php (L177)378944dd27/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php (L157)Is that the intended behaviour? Wouldn't it be better to clear
$resultin every loop cycle to free memory?If that's intended, is there a better way to loop through large result sets?
@beberlei commented on GitHub (Jan 6, 2021):
This is a bug
@simPod commented on GitHub (Jan 6, 2021):
@beberlei this looks like in order to fix https://github.com/doctrine/orm/issues/3238 we need to keep hydrated objects in memory so ObjectHydrator can look them up. Any idea? Seems like we can't have both to me 🤔