Professional OPC
Development Tools


Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

Data-COM Memory issue

14 May 2011 10:17 #374 by support
Replied by support on topic Re: Data-COM Memory issue

It would take some time to figure out precisely what is happening. I can see, however, some things in the code that are not fully correct, and can be related to the memory leak, so I suggest they are fixed first:

- VARIANTs v1 and v2 are not cleared. Either use VariantClear on them, or replace them by _variant_t or CComVariant
- Since v1 and v2 become owners of the SAFEARRAYs in tagNames and tagValues, the code should use CComSafeArray::Detach() to obtain the pointer to SAFEARRAY and at the same time remove the ownership from CComSafeArray.

Best regards

Please Log in or Create an account to join the conversation.

14 May 2011 10:16 #373 by support
From: R.
Sent: Friday, May 13, 2011 6:26 PM
Subject: Data-COM Memory issue
I have a customer who is complaining about a memory leak issue in the Data-COM. [.....] the application code is in VC++ [....] I haven’t been able to identify where in his code the memory increase is coming from. I have attached the sample application he sent me.

He says that if you run it as is, the memory increases- commenting out the WriteMultipleTags call causes the memory to be stable- so it is something in this routine I would guess. As far as I can tell he is destroying the tagValues and tagNames array each time- so it doesn’t seem to be from adding the tags continually to it. Any other ideas?

> ================================
> bool COpcClient::TestWriteBoolTags(const TCHAR * name1, const TCHAR * name2,
> bool val1, bool val2) {
> CComSafeArray tagValues;
> CComSafeArray tagNames;
> tagValues.Add(_variant_t(val1));
> tagNames.Add(CComBSTR(name1));
> tagValues.Add(_variant_t(val2));
> tagNames.Add(CComBSTR(name2));
> try {
> VARIANT v1, v2;
> VariantInit( &v1 );
> V_VT( &v1 ) = VT_ARRAY + VT_BSTR;
> SAFEARRAY * aNames = tagNames;
> V_ARRAY( &v1 ) = aNames;
> VariantInit( &v2 );
> V_VT( &v2 ) = VT_ARRAY + VT_VARIANT;
> SAFEARRAY * aValues = tagValues;
> V_ARRAY( &v2 ) = aValues;
> _variant_t varMachineNames(m_HostName);
> _variant_t varServerClasses(m_ServerName);
> _variant_t varStates=vtMissing;
> _variant_t varDataTypes=vtMissing;
> _variant_t varAccessPaths=vtMissing;
> VARIANT _result;
> VariantInit(&_result);
> HRESULT _hr =
> m_EasyDAClientPtr->raw_WriteMultipleItemValues(varMachineNames,
> varServerClasses,
> v1,
> v2,
> varStates,
> varDataTypes,
> varAccessPaths,
> &_result);
> if (FAILED(_hr)) _com_issue_errorex(_hr, m_EasyDAClientPtr,
> __uuidof(EasyDAClient));
> return true;
> }
> catch (_com_error e) {
> return false;
> }

Any help would be appreciated.


Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.045 seconds