Drop the container reference in LazyClassReflectionExtensionRegistryProvider after building the registry - #5985
Merged
Conversation
…rovider after building the registry Every ClassReflection instance holds this provider as a constructor dependency. Because the provider kept its Container reference for the whole process, every ClassReflection — and transitively every ObjectType that ever resolved its class, every ResolvedPhpDocBlock tag type, every cached signature — was a handle on the entire DI container. That reference is only needed once, to build the registry lazily. Null it out afterwards. Verified with retention-path instrumentation on a large project: no reference chain from ClassReflection to the container remains, which is a prerequisite for any future eviction of class reflections to actually free memory (and prevents a stale reflection from keeping a dead container alive, e.g. after stub validation). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NrTvR9j1mW2NNNC8RkuTsF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every
ClassReflectioninstance holdsClassReflectionExtensionRegistryProvideras a constructor dependency (ClassReflection.php), and the lazy provider kept itsContainerreference for the whole process — making everyClassReflection(and transitively everyObjectTypethat ever lazily resolved its class, everyResolvedPhpDocBlocktag type, every cached signature) a handle on the entire DI container.The reference is only needed once, to build the registry on first use. This PR nulls it out afterwards.
Found while instrumenting memory retention on a large project (ShipMonk backend): retention-path tracing repeatedly showed
... → ObjectType::$classReflection → ClassReflection::$classReflectionExtensionRegistryProvider → LazyClassReflectionExtensionRegistryProvider::$container → Container::$instances[] → everything, which (a) means a single stale reflection can keep a whole dead container alive (e.g. the stub validator's derived container, #5984), and (b) defeats any future eviction strategy for class reflections. After this change the instrumentation confirms no reference chain fromClassReflectionto the container remains.No behavioral change;
ClassReflectionTest,ClassTemplateTypeRuleTest,StubValidatorIntegrationTestpass, phpcs clean.🤖 Generated with Claude Code
https://claude.ai/code/session_01NrTvR9j1mW2NNNC8RkuTsF