Memory Allocation and Deletion in ISO C++
In the ISO C++ API, memory allocation and deletion is handled automatically. Entity classes (such as the ContentFilteredTopic) contain an underlying ‘smart pointer’ to keep track of the references to that particular instance of the class. Once there are no remaining references to the instance ( i.e. it falls out of scope ), the associated memory is deleted.
Manually Deallocating an Entities memory
Almost all Entities in isocpp2 have a close() function which can be used to manually release the instance memory associated with Data Readers / Writers / Topics etc. before the automatic clean up using smart pointers. However, Content Filtered Topics are a specialisation of the Topic Description class in isocpp2 and they do not contain this method.
So, if you try to manually close() an Entity while there is still a reference to a Content Filtered Topic within scope you will receive an error similar to:
terminate called after throwing an instance of ‘dds::core:reconditionNotMetError’
what(): Precondition not met: Topic still has unclosed dependencies (e.g. Readers/Writers/ContentFilteredTopics)
========================================================================================
Context : dds::core::Entity::close
Date : Sun Apr 24 10:07:17 UTC 2016
Node : localhost
Process : PicsInterface.out <705>
Thread : main thread 76d87000
Internals : TTopicImpl.hpp/236
—————————————————————————————-
Report : Precondition not met: Topic still has unclosed dependencies (e.g. Readers/Writers/ContentFilteredTopics)
Internals : dds::topic:etail::Topic<T>::close/TTopicImpl.hpp/236
Solution
One solution to avoid this error is to make the ContentFilteredTopic reference null before closing the Entity to ensure that the the main memory can be deallocated and the ContentFilteredTopic will be cleared up using the standard garbage collection methods.
i.e. my_contentFilteredTopic = dds::core::null;