Professional OPC
Development Tools

logos

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 in C++

More
27 Feb 2017 12:23 - 27 Feb 2017 12:23 #4974 by support
Replied by support on topic Memory leak in C++
I think you have misunderstood my reply. I have not recommended to deal with Windows messages; quite the opposite.

In effect, I have recommended that you do not use
CoInitialize(NULL);
and instead, use
CoInitializeEx(NULL, COINIT_MULTITHREADED);

in your program.

Best regards
Last edit: 27 Feb 2017 12:23 by support.

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

More
27 Feb 2017 11:56 - 27 Feb 2017 12:19 #4972 by olab
Replied by olab on topic Memory leak in C++
Hello,

I have to admit that I'm on thin ice here. I'm not a very experienced C++ programmer.

What Windows messages are wee talking about? What I actually need here is that the program connects to a server and read an opc item and return it to the value struct. Then the program is supposed to disconnect and start all over again. No need to any messages at all..
Last edit: 27 Feb 2017 12:19 by olab.

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

More
20 Feb 2017 10:06 #4968 by support
Replied by support on topic Memory leak in C++
One possible reason:

A COM thread in a single-threaded apartment (STA) *must* pump Windows messages. You have such thread (you call CoInitialize), but do not pump the messages.

The solution is either to make sure that thread pump messages (which, in many cases, is fairly complicated to do, and even more complicated to do it right), OR simply use a multi-threaded apartment (MTA): That is, call CoInitializeEx instead (msdn.microsoft.com/en-us/library/windows/desktop/ms695279(v=vs.85).aspx ), with COINIT_MULTITHREADED flag.

This is the first thing to do, it is surely wrong as it is now. If it continues to leak, there can be other reasons to it.

Best regards

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

More
14 Feb 2017 11:13 #4963 by olab
Memory leak in C++ was created by olab
Hello,
Attached code is a small program thas is supposed to connect to an opcserver and return one item with value, timestamp and quality. The program is called cyclically from a soft plc. Now I se that the program seems to leak memory. Can someone please tell me what to do to prevent this?

Kind regards

File Attachment:

File Name: C-Code.txt
File Size:6 KB
Attachments:

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

Moderators: support
Time to create page: 0.047 seconds