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.

Continuous instantiation of EasyUAClient causes ever-growing (?) memory usage

More
21 Nov 2023 13:28 #12390 by support
Note: QuickOPC now supports Python in much better way, cleaner syntax, and public packages (pypi.org/project/opclabs-quickopc/) on Python Package Index . See What's new in QuickOPC 2023.2 for more information. And, over 270 examples are available in the User's Guide!

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

More
25 Mar 2021 13:31 #9559 by support
Only call Dispose() on the instances you create. Do not call it on the shared instance.

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

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

More
25 Mar 2021 13:13 #9558 by mozesa
I am really grateful for the thorough explanation.

client = EasyUAClient()
client = EasyUAClient.SharedInstance

Is it OK to call client.Dispose() in both cases?

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

More
25 Mar 2021 12:53 #9556 by support
The drawbacks of using the shared instance only come to play if it is really shared between pieces of code that you do not have full control over. Because, each instance has some settings. And different pieces of code may require different settings, and their usage of the settings would then be in conflict.

If it is only "you" (your code) using the shared instance, it is fine then.

The memory is managed by .NET. The fact that it has grown from 90 MB to 1 GB does not, by itself, show anything. .NET may use the memory if there is memory available. It knows how much memory is there, and its consideration is not to let the others starving - but not to minimize the memory usage just for the sake of it.

There can be memory leak, yes. And the cause for the leak can be in QuickOPC, in your code, or in something in between (pythonnet) But the acceptable proof of the memory leak would be something like that a) the process runs out of memory, b) there is a clearly growing trend in memory usage - but for that I will need to see PerfMon chart over a longer period of time (process Private Bytes counter). I have seen situations e.g. that .NET's garbage collector (GC) decided to keep the memory slowly growing for approx. 3 days, and only then do some cleanup.

It may be worth calling client.Dispose() before it gets out of the function scope.

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

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

More
25 Mar 2021 12:12 #9554 by mozesa
*Hello*,

I am doing long running tests, and I noticed that my bare-bone python app memory usage was over 1 GB, it started from 90 MB.

I could boil down the issue to this code.
def write_value(server_url: str, node_id: str, value: Any) -> None:
    client = EasyUAClient()
    try:
        IEasyUAClientExtension.WriteValue(
            client,
            UAEndpointDescriptor(String(server_url)),
            UANodeDescriptor(String(node_id)),
            value,
        )
    except UAException as err:
        raise ClientError(err.ToString())

The write_value function is called continuously with 100 ms delay between invocations.

It seems to me as if each object of EasyUAClient would be added to a global collection.

Currently I use EasyUAClient.SharedInstance but I have read the drawbacks of it.

It is really my fault as I would have to instantiate only one EasyUAClient, I investigate further.

I would be appreciate if you could elaborate me on this EasyUAClient vs. EasyUAClient.SharedInstance topic.


I really appreciate your help.

Best Regards!

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

Moderators: support
Time to create page: 0.056 seconds