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.
Memory leak
Basically, in .NET you cannot expect the memory follow your wishes. It is managed by the .NET CLR and is not deterministic. Specifically, two memory consumption numbers taken at different times do not show anything. The memory consumption may easily drop down later. Allocating and deallocating an object does not mean the memory consumption will go down back to the same amount as before the allocation.
If you are still concerned, run PerfMon together with your app, and collect the necessary statistics over the long run (as shown in the link above, it usually has to be many days, over a week is preferred). Unless the graph shows a clean upward trend, there is no memory leak.
(If you do observe a clear upward trend, attach the collected data and we will look at it).
I would not comment to the use of Visual Leak Detector tool at all, because I do not know the tool and have no plans to look at it. I suspect its use is simply not appropriate to the kind of program we are dealing with.
Regarding your code, I have not spotted anything wrong (but a problem can still be there, too). Not that it is incorrect, but I would highly recommend to move the _EasyUAClientPtr outside of the function, and create it only once. It is a somewhat "heavy" object in terms of what it is needed to create it and or/destroy it, so frequent creations/destructions are not ideal.
Best regards
Please Log in or Create an account to join the conversation.
using Visual Leak Detector with your demo application "EasyOPCDADemo", the tool reports a lot of memory leaks...
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 329 at 0x068BF728: 24 bytes ----------
Leak Hash: 0xFBD82B5C, Count: 1, Total 24 bytes
Call Stack (TID 1028):
ntdll.dll!RtlReAllocateHeap()
Data:
46 00 45 00 44 00 45 00 52 00 49 00 43 00 41 00 F.E.D.E. R.I.C.A.
31 00 36 00 00 00 AD BA 1.6..... ........
[...]
---------- Block 51275 at 0x07A9D9D8: 1588 bytes ----------
Leak Hash: 0x0433ACAC, Count: 1, Total 1588 bytes
Call Stack (TID 9808):
ntdll.dll!RtlAllocateHeap()
Data:
20 B6 F4 06 01 00 00 00 68 00 00 01 E8 D9 A9 07 ........ h.......
5C 00 44 00 65 00 76 00 69 00 63 00 65 00 5C 00 \.D.e.v. i.c.e.\.
48 00 61 00 72 00 64 00 64 00 69 00 73 00 6B 00 H.a.r.d. d.i.s.k.
56 00 6F 00 6C 00 75 00 6D 00 65 00 34 00 5C 00 V.o.l.u. m.e.4.\.
57 00 69 00 6E 00 64 00 6F 00 77 00 73 00 5C 00 W.i.n.d. o.w.s.\.
61 00 73 00 73 00 65 00 6D 00 62 00 6C 00 79 00 a.s.s.e. m.b.l.y.
5C 00 70 00 75 00 62 00 70 00 6F 00 6C 00 38 00 \.p.u.b. p.o.l.8.
2E 00 64 00 61 00 74 00 0D F0 AD BA 0D F0 AD BA ..d.a.t. ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
---------- Block 51314 at 0x07A9E028: 1588 bytes ----------
Leak Hash: 0x0433ACAC, Count: 1, Total 1588 bytes
Call Stack (TID 9808):
ntdll.dll!RtlAllocateHeap()
Data:
20 B6 F4 06 01 00 00 00 7C 00 00 01 38 E0 A9 07 ........ |...8...
5C 00 44 00 65 00 76 00 69 00 63 00 65 00 5C 00 \.D.e.v. i.c.e.\.
48 00 61 00 72 00 64 00 64 00 69 00 73 00 6B 00 H.a.r.d. d.i.s.k.
56 00 6F 00 6C 00 75 00 6D 00 65 00 34 00 5C 00 V.o.l.u. m.e.4.\.
57 00 69 00 6E 00 64 00 6F 00 77 00 73 00 5C 00 W.i.n.d. o.w.s.\.
52 00 65 00 67 00 69 00 73 00 74 00 72 00 61 00 R.e.g.i. s.t.r.a.
74 00 69 00 6F 00 6E 00 5C 00 52 00 30 00 30 00 t.i.o.n. \.R.0.0.
30 00 30 00 30 00 30 00 30 00 30 00 30 00 30 00 0.0.0.0. 0.0.0.0.
30 00 35 00 2E 00 63 00 6C 00 62 00 0D F0 AD BA 0.5...c. l.b.....
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
Visual Leak Detector detected 996 memory leaks (942806 bytes).
Largest number used: 1496212 bytes.
Total allocations: 6841781 bytes.
Visual Leak Detector is now exiting.
The program '[7336] EasyOPCDADemo.exe: Native' has exited with code 0 (0x0).
Please Log in or Create an account to join the conversation.
I'm integrating your library inside my application.
I call "CoInitializeEx(NULL, COINIT_MULTITHREADED);" when I start my CWinApp application and "CoUninitialize();" when I close my application.
Then, the application enters inside a loop during which I call Read method; this is the function I call:
////////////////////////////////////////////////////////////////////////////////////////
void UAController::ReadValue(CString &usraddrs, CString &pwdaddrs, CString &serveraddrs, CString &valaddrs, CString &readValue)
////////////////////////////////////////////////////////////////////////////////////////
{
_bstr_t usrParam(usraddrs);
_bstr_t pwdParam(pwdaddrs);
_bstr_t serverParam(serveraddrs);
_bstr_t valueParam(valaddrs);
_EasyUAClientPtr ClientPtr(__uuidof(EasyUAClient));
try{
if(!usraddrs.IsEmpty() && !pwdaddrs.IsEmpty()) {
ClientPtr->Isolated = TRUE;
_EasyUAAdaptableParametersPtr IsolatedParameters = ClientPtr->GetIsolatedParameters();
_UASmartSessionParametersPtr SessionParms = IsolatedParameters->GetSessionParameters();
SessionParms->UserIdentity->UserNameTokenInfo->UserName = usrParam;
SessionParms->UserIdentity->UserNameTokenInfo->Password = pwdParam;
}
_UAAttributeDataPtr AttributeDataPtr = ClientPtr->Read(serverParam, valueParam);
if(AttributeDataPtr != NULL) {
// Display results
_variant_t vString;
vString.ChangeType(VT_BSTR, &AttributeDataPtr->Value);
readValue = vString.bstrVal;
}
}
catch (const _com_error& e)
{
CString desc( (LPCTSTR) e.Description());
CString errorMessage(e.ErrorMessage());
PrintLocalLog(FALSE, -1, _T("ERROR: %s"), desc);
}
}
Every time the application calls ReadValue function, the memory allocated to my process increses...
Where I mistake? Should I deallocate any structure?
Thanks!!
Any idea? After some hours, my program blocks my customer's pc.....
Please Log in or Create an account to join the conversation.