[5.4] Attempt to fix container bug #18812
Merged
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.
This is an attempt to fix the bug introduced in 5.4.16 as described in #18806
From my testing - it looks when resolving a singleton, the collection never pops the
$this->make[]
array - resulting in additional new arrays being constantly added to the existing array every time a call toresolve()
occurs. Because these new arrays are never released when resolving a singleton - it results in the run away memory usage.This is particularly noticeable in an Eloquent object, where calls that include date attribute casting can easily result in thousands of calls to
resolve()
- which keeps adding arrays to$this->make[]
, and never pops them off when finished.My testing shows memory returns to the same as
5.4.15
with this PR.My major concern; is there another effect on the container this PR might have that I'm not considering? Especially for the
makeWith()
functions?I ran through the container code - and I dont believe
$this->with
is ever touched until after the container confirms it is not resolving something that is already resolved as a singleton. So by moving it down until after the singleton test, we remove the increased memory usage...