Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[VarExporter] Fix possible memory-leak when using lazy-objects#48461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nicolas-grekas merged 1 commit intosymfony:6.2fromnicolas-grekas:lazy-weak
Dec 4, 2022

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedDec 3, 2022
edited
Loading

QA
Branch?6.2
Bug fix?yes
New feature?no
Deprecations?no
TicketsFix#48382
LicenseMIT
Doc PR-

I would have loved tonot store lazy-initializers in lazy objects, but this is not possible in PHP at the moment (seephp/php-src#10043 for details).

This PR moves storing state of lazy objects inside the objects themselves. This fixes the memory leak by allowing the garbage collector to free memory as needed. This has the drawback of adding noise whenvar_dump($lazyObject), but at least we can makedump($lazyObject) aware of that, thus the change on VarDumper.

@stephpy
Copy link
Contributor

👍 I can confirm you fixed a memory leak.

I had test on behat with symfony 6.1, with:2m35.82s (82.49Mb)

6.2 (tagged), i get2m24.30s (2.12Gb)

6.2.x-master on var-exporter component and I get2m37.99s (92.16Mb)

Looks nice :) Thanks.

@fabpotfabpot mentioned this pull requestDec 6, 2022
fabpot added a commit that referenced this pull requestDec 9, 2022
…r references in the container (nicolas-grekas)This PR was merged into the 6.3 branch.Discussion----------[DependencyInjection] Use WeakReference to break circular references in the container| Q             | A| ------------- | ---| Branch?       | 6.3| Bug fix?      | no| New feature?  | no| Deprecations? | no| Tickets       | -| License       | MIT| Doc PR        | -While working on#48461, I realized that we could break many circular loops involving the container by using a `WeakReference` to access it. This happens when we generate closures.Conceptually, we generate this at the moment:```php$internalClosure = function () { return $this->get('foo'); };```And we'd generate this with this PR:```php$containerRef = \WeakReference::create($this);$internalClosure = static function () use ($containerRef) { return $containerRef->get()->get('foo'); };```This should reduce the pressure on the garbage collector.Commits-------a3b7fca [DependencyInjection] Use WeakReference to break circular references in the container
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

6.2

Development

Successfully merging this pull request may close these issues.

3 participants

@nicolas-grekas@stephpy@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp