Skip to content

[HttpKernel] Avoid memory leak profiler #60933

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
param('profiler_listener.only_main_requests'),
])
->tag('kernel.event_subscriber')
->tag('kernel.reset', ['method' => 'reset'])

->set('console_profiler_listener', ConsoleProfilerListener::class)
->args([
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"symfony/error-handler": "^6.1|^7.0",
"symfony/event-dispatcher": "^5.4|^6.0|^7.0",
"symfony/http-foundation": "^6.4|^7.0",
"symfony/http-kernel": "^6.4",
"symfony/http-kernel": "^6.4.23",
"symfony/polyfill-mbstring": "~1.0",
"symfony/filesystem": "^5.4|^6.0|^7.0",
"symfony/finder": "^5.4|^6.0|^7.0",
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
6.4
---

* `Symfony\Component\HttpKernel\EventListener\ProfilerListener` is now resettable to prevent memory leaks
* Support backed enums in #[MapQueryParameter]
* `BundleInterface` no longer extends `ContainerAwareInterface`
* Add optional `$className` parameter to `ControllerEvent::getAttributes()`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Profiler\Profile;
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Symfony\Contracts\Service\ResetInterface;

/**
* ProfilerListener collects data for the current request by listening to the kernel events.
Expand All @@ -30,7 +31,7 @@
*
* @final
*/
class ProfilerListener implements EventSubscriberInterface
class ProfilerListener implements EventSubscriberInterface, ResetInterface
{
private Profiler $profiler;
private ?RequestMatcherInterface $matcher;
Expand Down Expand Up @@ -135,8 +136,7 @@ public function onKernelTerminate(TerminateEvent $event): void
$this->profiler->saveProfile($this->profiles[$request]);
}

$this->profiles = new \SplObjectStorage();
$this->parents = new \SplObjectStorage();
$this->reset();
}

public static function getSubscribedEvents(): array
Expand All @@ -147,4 +147,11 @@ public static function getSubscribedEvents(): array
KernelEvents::TERMINATE => ['onKernelTerminate', -1024],
];
}

public function reset(): void
{
$this->profiles = new \SplObjectStorage();
$this->parents = new \SplObjectStorage();
$this->exception = null;
}
}
Loading