public function clearExcept(array $keep): void
    {
        $kept = [];
        foreach ($keep as $name) {
            $name = $this->getDefinitiveName($name);

            if (!$this->has($name)) {
                throw NotFoundException::fromId($name);
            }

            $kept[$name] = $this->get($name);
        }

        $this->instances = $kept;
    }