public function handleShutdown(): void
    {
        if ($this->reservedMemory === null) {
            return;
        }

        $this->reservedMemory = null;

        // If an error has occurred that has not been displayed, we will create a fatal
        // error exception instance and pass it into the regular exception handling
        // code so it can be displayed back out to the developer for information.
        $error     = \error_get_last();
        $exception = null;

        if ($error !== null && self::isLevelFatal($error['type'])) {
            $trace = $error['backtrace'] ?? null;

            if (\strpos($error['message'], 'Allowed memory') === 0 || \strpos($error['message'], 'Out of memory') === 0) {
                $exception = new OutOfMemoryException(self::$levels[$error['type']] . ': ' . $error['message'], 0, $error['type'], $error['file'], $error['line'], 2, false, $trace);
            } else {
                // Create a new fatal exception instance from an error array.
                $exception = new FatalErrorException(self::$levels[$error['type']] . ': ' . $error['message'], 0, $error['type'], $error['file'], $error['line'], 2, true, $trace);
            }
        }

        if ($exception !== null) {
            $this->handleException($exception);
        }
    }