From 2fd33edf6caba82425d62589d47424def69d29e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Tue, 2 May 2023 15:17:12 +0200 Subject: [PATCH] fix: Fix the memory leak Closes #721. Follow up of [my comment](https://github.com/overblog/GraphQLBundle/issues/721#issuecomment-1414158275). I cannot investigate further, but my guess is that exceptions are not cheap objects. When creating an exception you also capture the context and stack trace which means that even if the extension is unsued: - it slows down the program because instantiating it is not cheap - may prevent some objects to be garbage collected because referenced in the exception --- src/ExpressionLanguage/ExpressionFunction.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ExpressionLanguage/ExpressionFunction.php b/src/ExpressionLanguage/ExpressionFunction.php index 2bd938003..09153a046 100644 --- a/src/ExpressionLanguage/ExpressionFunction.php +++ b/src/ExpressionLanguage/ExpressionFunction.php @@ -12,7 +12,9 @@ class ExpressionFunction extends BaseExpressionFunction public function __construct(string $name, callable $compiler, ?callable $evaluator = null) { if (null === $evaluator) { - $evaluator = new EvaluatorIsNotAllowedException($name); + $evaluator = static function (string $name) { + throw new EvaluatorIsNotAllowedException($name); + }; } parent::__construct($name, $compiler, $evaluator);