DdsPublisherRepository::~DdsPublisherRepository() throw()
  {
    // just to make sure, the repository should actually be empty at this point.
    InstanceMap::iterator first, last = instances_.end();
    for (first = instances_.begin(); first != last; ++first) {
      //      delete first->second;
      DDS::Publisher * pub = dynamic_cast<DDS::Publisher *>(first->second);
      DDS::DomainParticipant * participant = pub->get_participant();
      DDS::ReturnCode_t rc = participant->delete_publisher(pub);

      if (rc != DDS_RETCODE_OK) {
        MIRO_LOG_OSTR(LL_ERROR, "Error deleting DDS publisher: " << DdsSupport::getError(rc));
      }
    }
  }
  void
  DdsPublisherRepository::remove(std::string const& name)
  throw(ENotRegistered)
  {
    InstanceMap::iterator i = instances_.find(name);
    if (i != instances_.end()) {
      //delete i->second;
      DDS::Publisher * pub =  dynamic_cast<DDS::Publisher *>(i->second);
      DDS::DomainParticipant * participant = pub->get_participant();
      DDS::ReturnCode_t rc = participant->delete_publisher(pub);

      if (rc != DDS_RETCODE_OK) {
        MIRO_LOG_OSTR(LL_ERROR, "Error deleting DDS publisher: " << DdsSupport::getError(rc));
      }

      instances_.erase(i);
      if (instances_.size() == 0)
        SingletonType::ACE_Singleton_Type::close();
      return;
    }
    throw ENotRegistered(name);
  }