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.

EasyDAClient Memory Leak.

More
07 Dec 2022 17:39 #11317 by IRuiz
Replied by IRuiz on topic EasyDAClient Memory Leak.
Just to confirm I am not able to reproduce any of the original cases with the example you provided.

Thanks.

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

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

More
07 Dec 2022 16:08 #11316 by support
Replied by support on topic EasyDAClient Memory Leak.
Hello.
My project is in the attachment.

Best regards

File Attachment:

File Name: QuickOPC_Leak2.zip
File Size:6 KB
Attachments:
The following user(s) said Thank You: IRuiz

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

More
07 Dec 2022 15:45 #11315 by IRuiz
Replied by IRuiz on topic EasyDAClient Memory Leak.
Hello,

I went ahead and followed the advice about not implementing my own EasyDAClient pool and just share one instance across our own Connection objects, this seems to be working fine and I've seen no memory increase at all, even after reinitializing TopServer several times. Still, I'd appreciate if you could share the modified test project you ended up using.

Thanks for the support,

Regards

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

More
07 Dec 2022 13:39 #11314 by support
Replied by support on topic EasyDAClient Memory Leak.
Hello.
I attempted to reproduce the issue, but have not succeeded. This was done with Release x64 build, outside of Visual Studio, with no OPC connection interruptions.

Here is the result of my test run, over the course of 3 hours. It shows no signs of memory leak.



For record, there were following differences (known to me) from your test:

1. I updated the referenced version of QuickOPC package to the recent one (2022.2) available as of today. In the process, I changed the format of references from "packages.config" to the new "Package Reference".
2. Switched the project to target .NET Framework 4.7.2, as it is the new minimum required by the current version.
3. Replaced the initialization of ServerDescriptor by a single call to "new ServerDescriptor("...")", because the particular overload of ServerElement you wer eusing is no longer present in the current version, and it was unnecessary to use ServerElement there.
4. Added some diagnostics output (Console.WriteLine) to better indicate operation failures, and count the number of EasyDAClient objects in use at any particular moment.

I do not think that differences #2, 3, or 4 have any significance. Difference #1 may be the cause; we have not specifically fixed any memory leak between your version and ours, but there were lots of changes everywhere, so it is always a possibility that it is gone now. Another explanation is that there is some other difference that I do not know about.

Either way, until I have a reproducible scenario, there is nothing else I can do.

Best regards
Attachments:

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

More
07 Dec 2022 09:37 - 07 Dec 2022 09:41 #11311 by support
Replied by support on topic EasyDAClient Memory Leak.
There are multiple reasons for EasyDAClient existing as an IDisposable object and not a set of static methods (leaving aside that we are doing OOP and static methods are not "nice"). Not everybody is affected by these reasons, but they are all very important, and some of them are:

1. There is no direct way to expose static classes/methods to COM, and our product can be used from COM tools and languages as well.

2. Although the EasyDAClient, by default, manages connections, in what appears a "shared" mode, it also has some per-instance settings (see the Reference doc). So some users may want separate instances because of the need to have different some of these per-instance settings. And you may set it to "Isolated" mode, in which the connections created by that instance will not be shared by other instances. So you have a complete flexibility, in case you need it. But normally you don't.

3. For developers using VS designer, such as in WinForms, you need to have a way to drag the EasyDAClient to the designer surface from the toolbox. For it, it has to be a true object (not a static class). And it has to derive from Component, which means it must be IDisposable.

4. The SharedInstance is for ease of use. It is fine to use it in non-library projects, because you know you are the only one using it. But if you are writing a library, you would be risking that the per-instance settings will conflict with somebody else's. This is all explained in the doc.

Regards
Last edit: 07 Dec 2022 09:41 by support.

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

More
06 Dec 2022 15:43 #11309 by support
Replied by support on topic EasyDAClient Memory Leak.
Thank you.

I want to note that what you are doing with the pool is not needed either. One EasyDAClient can connect to multiple servers. You are writing code for what is already in the product.

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

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

More
06 Dec 2022 15:40 #11308 by IRuiz
Replied by IRuiz on topic EasyDAClient Memory Leak.
'In your report, you describe what happens running the Debug x64 configuration inside VS, and Release x64 outside VS. Have you also tried at least one of the remaining combinations (Debug x64 outside VS, or Release x64 inside VS), and if so, what were the results?'

- Both leak.

Regarding the EasyDAClient object, if the connections are managed inside by the library, then why expose the EasyDAClient as a standalone IDIsposable class at all? It'd make more sense to then just have it expose static methods for Read/Write/Browse operations giving in some configuration object parameter, it sounds more like a shared instance and yet again it is discouraged to also use the EasyDAClient.SharedInstance too.

In the meantime I was able to stop the leaks by implementing our own EasyDAClient pool given a ServerDescriptor hash, so any driver pointing to the same opcda endpoint will end up using the same EasyDAClient ref.

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

More
06 Dec 2022 14:12 #11306 by support
Replied by support on topic EasyDAClient Memory Leak.
Hello.

Regarding "...so we need to be able to Open, Close, Read, Write and somehow recreate the connection if errors are being thrown" : Still, this is misunderstanding of how EasyDAClient works. You do not achieve "recreating the connections" by disposing of the EasyDAClient. The connections are independent of that. EasyDAClient manages the connections automatically, and recreates them as needed. But anyway, you can of course dispose of the EasyDAClient it if you like. But it is totally useless in this respect. What influences when the connections are created and removed are the operations on the EasyDAClient objects (reads, writes, subscriptions), and not the object creation and disposal.

I rebuilt your project and will be running the tests. I will let you know then.

In your report, you describe what happens running the Debug x64 configuration inside VS, and Release x64 outside VS. Have you also tried at least one of the remaining combinations (Debug x64 outside VS, or Release x64 inside VS), and if so, what were the results?

Regards

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

More
05 Dec 2022 20:26 #11302 by IRuiz
Replied by IRuiz on topic EasyDAClient Memory Leak.
Hi, thanks for replying,

1- I understand this, still, having a Dispose() method implies that any resources including unmanaged should be freed, so yeah, It might be discouraged just because of how you handle internal static states but I think it should still work. In our software, communication drivers are plugins and they do need to represent a 'connection' object, so we need to be able to Open, Close, Read, Write and somehow recreate the connection if errors are being thrown. It does seems like the ONLY way to keep it from leaking is to have 1 EasyDAClient instance without disposing it ever, what if in our software user can Start/Stop communications, modify the endpoints, then I just modify the Descriptor and keep using the old EasyDAClient object? We have a lot of other drivers for other type of protocols, and all of them, either proprietary or thrid library like nmodbus are able to properly free the memory upon Disposing w.e type of wrapper they offer. Some do require a garbage collector forced call but end up freeing memory.

2. There is a screenshot attached in which the memory went over 5 gigabytes in a period of 2 days, so its not a matter of timing, it just never releases memory.

3. Its just a way to make sure the parent thread caller never hangs beyond user configured timeouts no matter what.

Best regards,

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

More
05 Dec 2022 20:05 #11300 by support
Replied by support on topic EasyDAClient Memory Leak.
Hello.
I will have a look at it. Please allow some time. I have some comments too:

1. Not only it is not necessary to dispose of the EasyDAClient after each operation, it is also not necessary (in fact, it is highly discouraged) to dispose of it because you detected some failure. Doing so is a misunderstanding of the QuickOPC concept. The EasyDAClient does *not* represent a connection. The principles of operation are described in the User's Guide. For an application like the one in your example, you can simple create and keep using a single EasyDAClient object. But I understand this rule/recommendation does not invalidate the point about memory leak.

2. There are conflicting requirements to the object disposal:
- Users want that the disposal works synchronously; i.e. does not return after it is done, and after it returns, resources are cleaned up.
- Users want that the disposal does never "block".
Unfortunately, these two requirements are at direct conflict, when you think it through, and cannot be fulfilled together. I think our current implementation prefers the quick return from the Dispose(), which means that the actual resource disposal can lag behind.

3. I think I have seen conflicts of the Task mechanism with EasyDAClient. Is there a particular reason you are using it, or have to use it?

4. Our current version is QuickOPC 2022.2 (5.70). This is what I will test with. If this issue results in some code change, it will be done into version 2022.2. We do not update older versions.

Best regards

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

Moderators: support
Time to create page: 0.062 seconds