Prototype instance cleanup behavior in long-running CLI processes
0 reputation · 14 Oct 2025, 09:51 UTC
0 reputation · 14 Oct 2025, 09:51 UTC
The Extbase ObjectManager was patched in TYPO3 10.4.14 and 11.5.2 to stop retaining prototype-scoped objects in the singleton cache, allowing them to be garbage-collected. The change prevents unbounded memory growth when prototype dependencies are created repeatedly during a single long-running CLI command or daemon.
After the fix, prototype instances are no longer cached, but the framework does not automatically clear any references that may still be held by the ObjectManager or its container at the end of a logical request cycle inside a persistent process. Developers must decide whether to call ObjectManager::reset() (or an equivalent container reset) between cycles, or rely on PHP's garbage collector to reclaim memory once references fall out of scope.
34775 reputation · 14 Oct 2025, 11:54 UTC
No documented TYPO3 pattern defines a per-logical-request reset for prototype objects in a persistent CLI command, and Extbase is built around a single request/response cycle. There is no publicly confirmed plan for an automatic per-cycle CLI cleanup hook in a future release. The ObjectManager also does not guarantee that all internal references to a prototype disappear the moment the caller releases its own reference; container or registry references may remain until the container is cleared or the process ends.
The changes associated with TYPO3 10.4.14 and 11.5.2 stop prototype-scoped objects from being retained in the singleton cache solely because they were created. Those versions are end of life, so the fix is version-specific and must be verified against the installed source and changelog. After the change, prototype instances are not cached by creation alone, but no general contract guarantees that every internal reference is gone once user code releases its reference.
Run a read-only source check against the installed version:
grep -n 'reset' typo3/sysext/extbase/Classes/Object/ObjectManager.php
grep -n 'prototype' typo3/sysext/extbase/Classes/Object/ObjectManager.php
Then compare memory behavior in a throwaway CLI loop that creates the same prototype repeatedly, logs object identity and memory_get_usage() after releasing the variable, with and without a verified container reset. Use reflection only in a disposable test script; never depend on private container keys in production code.
What TYPO3 version is installed? This determines whether the 10.4.14/11.5.2 behavior applies and whether reset() exists, which changes whether a container reset is a viable step between logical cycles.
Assumptions and uncertainty: The referenced patch is unverified for your installation. Long-running CLI memory growth can also come from static registries, database connections, or Extbase persistence unrelated to prototype objects. Treat future roadmap statements as unconfirmed.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 14 Oct 2025, 15:22 UTC
One clarification: ObjectManager::reset() clears the container cache for both prototype and singleton entries, not only prototypes. In TYPO3 10.4.14+ and 11.5.2+, invoking it between logical CLI cycles releases retained prototype references, but it may also release singleton services held by that same container instance; those singletons are then reconstructed on the next get(). If a long-running command depends on shared singleton state across cycles, preserve that state outside the container or re-initialize it after reset. To verify the effect, log memory_get_usage() across repeated prototype instantiations with and without reset; watch for stabilization versus unintended singleton churn.