(Note: in the Modern C++ API, Entities are automatically destroyed, see Creating and Deleting DDS Entities)
To delete a single DataWriter, use the Publisher’s delete_datawriter() operation:
DDS_ReturnCode_t delete_datawriter ( DDSDataWriter *a_datawriter)
Note: A DataWriter cannot be deleted within its own writer listener callback, see Restricted Operations in Listener Callbacks
To delete all of a Publisher's DataWriters, use the Publisher's delete_contained_entities() operation (see Deleting Contained DataWriters).
This section only applies when the DataWriter’s DestinationOrderQosPolicy’s kind is BY_SOURCE_TIMESTAMP.
Calls to delete_datawriter() may fail if your application has previously used the “with timestamp” APIs (write_w_timestamp(), register_instance_w_timestamp(), unregister_instance_w_timestamp(), or dispose_w_timestamp()) with a timestamp that is larger than the time at which delete_datawriter() is called.
To prevent delete_datawriter() from failing in this situation, either:
writer_qos.writer_data_lifecycle. autodispose_unregistered_instances = DDS_BOOLEAN_FALSE;
or
© 2018 RTI