Skip to content

Commit bea0ae9

Browse files
bug #48461 [VarExporter] Fix possible memory-leak when using lazy-objects (nicolas-grekas)
This PR was merged into the 6.2 branch. Discussion ---------- [VarExporter] Fix possible memory-leak when using lazy-objects | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #48382 | License | MIT | Doc PR | - I would have loved to *not* store lazy-initializers in lazy objects, but this is not possible in PHP at the moment (see php/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 when `var_dump($lazyObject)`, but at least we can make `dump($lazyObject)` aware of that, thus the change on VarDumper. Commits ------- ce1ff9f700 [VarExporter] Fix possible memory-leak when using lazy-objects
2 parents 3023cad + 1a69670 commit bea0ae9

File tree

3 files changed

+3
-13
lines changed

3 files changed

+3
-13
lines changed

Dumper/PhpDumper.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
3030
use Symfony\Component\DependencyInjection\Exception\LogicException;
3131
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
32-
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
3332
use Symfony\Component\DependencyInjection\ExpressionLanguage;
3433
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface as ProxyDumper;
3534
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\LazyServiceDumper;
@@ -168,15 +167,7 @@ public function dump(array $options = []): string|array
168167

169168
if ($this->getProxyDumper() instanceof NullDumper) {
170169
(new AnalyzeServiceReferencesPass(true, false))->process($this->container);
171-
try {
172-
(new CheckCircularReferencesPass())->process($this->container);
173-
} catch (ServiceCircularReferenceException $e) {
174-
$path = $e->getPath();
175-
end($path);
176-
$path[key($path)] .= '". Try running "composer require symfony/proxy-manager-bridge';
177-
178-
throw new ServiceCircularReferenceException($e->getServiceId(), $path);
179-
}
170+
(new CheckCircularReferencesPass())->process($this->container);
180171
}
181172

182173
$this->analyzeReferences();

Tests/Dumper/PhpDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ public function testCircularReferenceAllowanceForLazyServices()
765765
$dumper = new PhpDumper($container);
766766
$dumper->setProxyDumper(new NullDumper());
767767

768-
$message = 'Circular reference detected for service "foo", path: "foo -> bar -> foo". Try running "composer require symfony/proxy-manager-bridge".';
768+
$message = 'Circular reference detected for service "foo", path: "foo -> bar -> foo".';
769769
$this->expectException(ServiceCircularReferenceException::class);
770770
$this->expectExceptionMessage($message);
771771

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
"symfony/yaml": "",
3232
"symfony/config": "",
3333
"symfony/finder": "For using double-star glob patterns or when GLOB_BRACE portability is required",
34-
"symfony/expression-language": "For using expressions in service container configuration",
35-
"symfony/proxy-manager-bridge": "Generate service proxies to lazy load them"
34+
"symfony/expression-language": "For using expressions in service container configuration"
3635
},
3736
"conflict": {
3837
"ext-psr": "<1.1|>=2",

0 commit comments

Comments
 (0)