You are here: Part 2: Core Concepts > Receiving Data > Subscribers > Deleting Subscribers

Deleting Subscribers

(Note: in the Modern C++ API, Entities are automatically destroyed, see Creating and Deleting DDS Entities)

This section applies to both implicitly and explicitly created Subscribers.

To delete a Subscriber:

  1. You must first delete all DataReaders that were created with the Subscriber. Use the Subscriber’s delete_datareader() operation (Creating DataReaders) to delete them one at a time, or use the delete_contained_entities() operation (Deleting Contained DataReaders) to delete them all at the same time.
DDS_ReturnCode_t delete_datareader (DDSDataReader *a_datareader)
  1. Delete the Subscriber by using the DomainParticipant’s delete_subscriber() operation ().

Note: A Subscriber cannot be deleted within a listener callback, see Restricted Operations in Listener Callbacks.

Deleting Contained DataReaders

The Subscriber’s delete_contained_entities() operation deletes all the DataReaders that were created by the Subscriber. It also deletes the ReadConditions created by each contained DataReader.

DDS_ReturnCode_t DDSSubscriber::delete_contained_entities () 

After this operation returns successfully, the application may delete the Subscriber (see Deleting Subscribers).

The operation will return PRECONDITION_NOT_MET if any of the contained entities cannot be deleted. This will occur, for example, if a contained DataReader cannot be deleted because the application has called read() but has not called the corresponding return_loan() operation to return the loaned DDS samples.

© 2016 RTI