function clearRefBag(int $timeout) {
        $time = \time() - $timeout;
        
        foreach($this->refBag as $id => $timestamp) {
            if($timestamp <= $time) {
                unset($this->refBag[$id]);
            }
        }
        
        if(\count($this->refBag) === 0 && $this->stack->count() === 0) {
            $this->bag->lastEmptyStack = \time();
            $this->bag->currentlyBusy = false;
            
            $msg = new \CharlotteDunois\Phoebe\Message('internal-worker-stack-free', null);
            $this->sendMessageToPool($msg);
        }
    }