I just spent way too much time chasing an out of memory error when running one of my Symfony Commands. Apparently the Doctrine ORM was holding on to too many entities. I tried flushing, clearing, all the usual stuff, but nothing worked.
Turns out, when running Symfony commands via php bin/console <command-name>, Doctrine's BacktraceDebugDataHolder is used, which NEVER DELETES ENTITIES.
This was news to me too. Simply appending --no-debug disables this & seems to fix the issue.
I wish this was made more obvious.