How to delete memory allocated for UaDataValue object

Questions regarding the use of the C++ SDK for Server or Client development or integration into customer products ...

Moderator: uasdkcpp

Post Reply
Antoni Raj
Hero Member
Hero Member
Posts: 33
Joined: 25 Oct 2013, 05:26

How to delete memory allocated for UaDataValue object

Post by Antoni Raj »

Hi Support Team,
We are using Unified Automation UA SDK C++ Server Professional 1.6.3 in our OPC UA server. We use visual studio 2015 for our development.
We are following sample server “server_com_da_migration” for our OPC server development.
We have our own NodeManager implementation.

Below is code snippet in the executeRead() method. This executeRead() method is called every 10 millisecond.
We are afraid that the dataValue of type UaDataValue will cause memoryleak. Because every 10 millisecond one object of type UaDataValue is created.

void OPCUAIOManagerJob::executeRead()
{

UaDataValue dataValue;
------
-----
----

dataValue.setServerTimestamp(UaDateTime::now());
m_pTransactionContext->m_pCallback->finishRead(
m_pTransactionContext->m_hTransaction,
m_pTransactionContext->m_arrCallbackHandles,
dataValue,
OpcUa_True,
OpcUa_True);

VariantClear(&pValues);
dataValue.clear();

-----
-----
}


Question:
1. How to delete the memory allocated for UaDataValue ? Does it taken care by tool kit.?
2. We tried using dataValue.clear( ) as shown in code snippet. But the read is not successful.


Please help us on this.Thanks in advance for the help.

Thanks
Antoni

User avatar
Support Team
Hero Member
Hero Member
Posts: 2519
Joined: 18 Mar 2011, 15:09

Re: How to delete memory allocated for UaDataValue object

Post by Support Team »

Hello Antoni,

in the code you posted you use a local variable dataValue. So the destructor of UaDataValue will be called when execution leaves that scope.
The destructor of UaDataValue clears all resources used by that class. There's no need to explicitly call dataValue.clear() here.

Do you observe any memory leaks or are you just wondering if that could happen?
Best regards
Unified Automation Support Team

Antoni Raj
Hero Member
Hero Member
Posts: 33
Joined: 25 Oct 2013, 05:26

Re: How to delete memory allocated for UaDataValue object

Post by Antoni Raj »

Hi Team,
Thank you very much for your quick response . I appreciate it.
No . I am not facing any memory leaks. Just asking for clarification.

Thank you again

Regards
Antoni

Post Reply