diff --git a/src/Knp/Snappy/AbstractGenerator.php b/src/Knp/Snappy/AbstractGenerator.php index 529bc7c..0e9a6c7 100644 --- a/src/Knp/Snappy/AbstractGenerator.php +++ b/src/Knp/Snappy/AbstractGenerator.php @@ -7,9 +7,10 @@ use Psr\Log\LoggerAwareTrait; use Symfony\Component\Process\Process; use Exception; +use InvalidArgumentException; use LogicException; use RuntimeException; -use InvalidArgumentException; +use WeakReference; /** * Base generator class for medias. @@ -74,7 +75,10 @@ public function __construct($binary, array $options = [], array|null $env = null $this->env = empty($env) ? null : $env; if (\is_callable([$this, 'removeTemporaryFiles'])) { - \register_shutdown_function([$this, 'removeTemporaryFiles']); + $ref = WeakReference::create($this); + \register_shutdown_function(static function () use ($ref): void { + $ref->get()?->removeTemporaryFiles(); + }); } }