Professional OPC
Development Tools

logos

Can Develop OPC XML DA C++ client in Visual Studio 2015?

More
29 Nov 2016 15:05 - 29 Nov 2016 15:09 #4606 by Vasanth
Hi,

Attached performance counter file and its running around 40 mins only after that its crashing (out of memory exception), at that time of crash, memory is 1.6 GB. Every 1.6 GB of memory leak this exception is reproduced very well, refer attached image of exception too.

Please do let me know the solution ASAP, My Management is pushing me address this at earliest.
Thanks for understanding.


File Attachment:

File Name: Performanc...nter.zip
File Size:7 KB
Attachments:
Last edit: 29 Nov 2016 15:09 by Vasanth. Reason: Missing file

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

More
29 Nov 2016 08:53 #4605 by support
Please provide a picture of the growing trend of memory consumption in long term (several hours at least).

Use PERFMON, the "Private bytes" counter for the process.

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

More
29 Nov 2016 07:10 - 29 Nov 2016 17:31 #4604 by Vasanth
Hi,

Still Memory leak is there, In 1 minute below code reaches to 3.5 MB. I have incorporated your change and put while loop in sample ReadMultipleItems. Could you please check the issue.
while(1){
 
		_DAReadItemArgumentsPtr ReadItemArguments1Ptr(_uuidof(DAReadItemArguments));
		ReadItemArguments1Ptr->ServerDescriptor->ServerClass = L"OPCLabs.KitServer.2";
		ReadItemArguments1Ptr->ItemDescriptor->ItemId = L"Simulation.Random";
 
		_DAReadItemArgumentsPtr ReadItemArguments2Ptr(_uuidof(DAReadItemArguments));
		ReadItemArguments2Ptr->ServerDescriptor->ServerClass = L"OPCLabs.KitServer.2";
		ReadItemArguments2Ptr->ItemDescriptor->ItemId = L"Trends.Ramp (1 min)";
 
		_DAReadItemArgumentsPtr ReadItemArguments3Ptr(_uuidof(DAReadItemArguments));
		ReadItemArguments3Ptr->ServerDescriptor->ServerClass = L"OPCLabs.KitServer.2";
		ReadItemArguments3Ptr->ItemDescriptor->ItemId = L"Trends.Sine (1 min)";
 
		_DAReadItemArgumentsPtr ReadItemArguments4Ptr(_uuidof(DAReadItemArguments));
		ReadItemArguments4Ptr->ServerDescriptor->ServerClass = L"OPCLabs.KitServer.2";
		ReadItemArguments4Ptr->ItemDescriptor->ItemId = L"Simulation.Register_I4";
 
		CComSafeArray<VARIANT> ArgumentsArray(4);
		ArgumentsArray.SetAt(0, _variant_t((IDispatch*)ReadItemArguments1Ptr));
		ArgumentsArray.SetAt(1, _variant_t((IDispatch*)ReadItemArguments2Ptr));
		ArgumentsArray.SetAt(2, _variant_t((IDispatch*)ReadItemArguments3Ptr));
		ArgumentsArray.SetAt(3, _variant_t((IDispatch*)ReadItemArguments4Ptr));
 
		LPSAFEARRAY pArgumentsArray = ArgumentsArray.Detach();
		//CComSafeArray<VARIANT> ResultArray(ClientPtr->ReadMultipleItems(&pArgumentsArray));
	[b]	CComSafeArray<VARIANT> ResultArray;
		ResultArray.Attach(ClientPtr->ReadMultipleItems(&pArgumentsArray));[/b]
		ArgumentsArray.Attach(pArgumentsArray);
 
		for (int i = ResultArray.GetLowerBound(0); i <= ResultArray.GetUpperBound(0); i++)
		{
			_DAVtqResultPtr DAVtqResultPtr(ResultArray[i]);
			_DAVtqPtr DAVtqPtr(DAVtqResultPtr->Vtq);
			_variant_t vtqAsString(DAVtqPtr->ToString);
			_tprintf(_T("results(%d).Vtq.ToString(): %s\n"), i, vtqAsString.bstrVal);
		}
 
		// Release all interface pointers BEFORE calling CoUninitialize()
		ResultArray.Detach();
		ResultArray.Destroy();
		ArgumentsArray.Detach();
		ArgumentsArray.Destroy();
	}
Last edit: 29 Nov 2016 17:31 by support.

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

More
27 Nov 2016 15:22 #4599 by support
The memory leak comes from the assignment to ResultArray.
It should instead be written like this:
CComSafeArray<VARIANT> ResultArray;
ResultArray.Attach(ClientPtr->ReadMultipleItems(&pArgumentsArray));
This bug was already in the example code we have provided, so we will fix the example(s). There is no indication of a memory leak in the component itself.

Regards
The following user(s) said Thank You: Vasanth

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

More
25 Nov 2016 11:24 #4597 by Vasanth
Hi,

Do you guys have any update for me?

Thanks.

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

More
22 Nov 2016 18:15 #4587 by support
I will try to reproduce the problem here, using the code parts you have sent. Please allow some time for it, as I am out of office and have appointments some days.

Best regards
The following user(s) said Thank You: Vasanth

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

More
22 Nov 2016 09:52 - 23 Nov 2016 16:47 #4585 by Vasanth
Hi,

Below code is consistently growing up even after destroying it, How do I clear the memory for pArgumentsArray, ResultArray and ArgumentsArray. I doubt its destroying array but memory is not cleaned.

I call this thread for every 5, 26 secs and 1 subscription based thread also running. When I enter this point of code memory is growing up then after its not reducing at all.

I just checked by running ExampleCOM - ReadMultipleItems for memory, its also taking 16+MB.
Since, I am licensed user can I get different version of QuickOPC libraries where I can get reduced memory leak.

When I run this application in client environment within 1 hour it reaches to 100MB and in 12 hours it goes more then 1GB which is not acceptable by my customer.

Please help me to solve this issue.

_EasyDAClientPtr ClientPtr(__uuidof(EasyDAClient)); ---> This line grows up almost 13MB after that its not freed at all. In my code I am calling only once to check server connection, read multiple items and subscribe multiple items.

for (int i = 0; i < noOftags; i++)
{
_DAReadItemArgumentsPtr ReadItemArguments1Ptr(_uuidof(DAReadItemArguments));
ReadItemArguments1Ptr->ServerDescriptor->UrlString = urlString.m_str;
ReadItemArguments1Ptr->ItemDescriptor->ItemId = itemIds.m_str;
ArgumentsArray.SetAt(i, _variant_t((IDispatch*)ReadItemArguments1Ptr));
}

LPSAFEARRAY pArgumentsArray = ArgumentsArray.Detach();
CComSafeArray<VARIANT> ResultArray(ClientPtr->ReadMultipleItems(&pArgumentsArray)); ----> This line grows up almost 1.2MB each time.
ArgumentsArray.Attach(pArgumentsArray);

ResultArray.Destroy();
ArgumentsArray.Destroy();
//SafeArrayDestroy(pArgumentsArray);
Last edit: 23 Nov 2016 16:47 by Vasanth. Reason: added some more input

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

More
21 Nov 2016 14:55 #4584 by support
Given that there are OutOfMemoryException-s, have you observed whether the memory consumed by the application grows unreasonably, using tools such as PerfMon? Note that OutOfMemoryException-s are sometimes caused by reasons not related to memory, so this is the first thing to check.

If the memory consumed by the process truly grows beyond reasonable amounts (how much?), then try to determine which part(s) of the code are responsible. There are tools that tell you where the allocations are being made. You can also comment out parts of the code and observer the effect is has. For example, if you are using subscriptions, the first candidate would be to comment out the whole body of the event handler, to see if it's coming from there.

Mind you, it is fairly easy to cause a memory leak in C or C++.
The following user(s) said Thank You: Vasanth

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

More
21 Nov 2016 09:57 #4583 by Vasanth
Hi,

Thanks for the input.

I application crashed after 36 hours and gave error logs is QuickOPC libaries. Could you please check and help me solve this issue or any clue to fix these issues.

I have customized error logs for better reading and attached the same.

Thanks.


File Attachment:

File Name: Customized..._Log.txt
File Size:7 KB
Attachments:

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

More
19 Nov 2016 10:49 #4581 by support
QuickOPC will always deliver the notifications to you one by one, and they are not grouped in any way, if that was the question.
The following user(s) said Thank You: Vasanth

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

Moderators: support
Time to create page: 0.238 seconds

      

 Recommend this on Google