I'm told that DDS maintains a reference to DTOs created when using the example code here:
public void on_data_available(DataReader reader) {
HelloWorldDataReader HelloWorldReader =
(HelloWorldDataReader)reader;
try {
HelloWorldReader.take(
_dataSeq, _infoSeq,
ResourceLimitsQosPolicy.LENGTH_UNLIMITED,
SampleStateKind.ANY_SAMPLE_STATE,
ViewStateKind.ANY_VIEW_STATE,
InstanceStateKind.ANY_INSTANCE_STATE);
for(int i = 0; i < _dataSeq.size(); ++i) {
SampleInfo info = (SampleInfo)_infoSeq.get(i);
if (info.valid_data) {
System.out.println(
((HelloWorld)_dataSeq.get(i)).toString("Received",0));
}
}
} catch (RETCODE_NO_DATA noData) {
// No data to process
} finally {
HelloWorldReader.return_loan(_dataSeq, _infoSeq);
}
}
}
Do I need to use the copy_from method prior to passing the DTO to the rest of my code? The explanation given was that RTI maintains a reference to the DTO and will simply update the fields when new data is received instead of creating a new HelloWorld DTO. The explanation stated the DTOs wouldn't operate properly unless it was explicitely released by first performing a copy (so I'm not holding a reference to the original) and calling return_loan on the reader. This doesn't make sense to me as I'd expect the references to be cleared once the sequence is cleared.
Is this accurate? Do I actually need to copy every single time a DTO comes in? I'd prefer to minimize overhead if possible since these DTOs will be sent at a relatively high rate.