Professional OPC
Development Tools

logos

Potential Memory Leak? (Python)

More
22 Nov 2017 15:48 - 22 Nov 2017 15:48 #5683 by support
From: Z.
Sent: Tuesday, November 21, 2017 11:37 PM
To: C.
Subject: RE: Potential Memory Leak?

C.,

I do not know Python that well, but apparently the leak has to do with the way the program is written. The ‘doWork’ procedure used ‘threading.Timer’ calls to call itself again (a kind of recursion), and it looks like that in code invoked in this way, the COM arguments allocated by the caller are not released properly.

When you rewrite the bottom part of the program into a traditional loop, the memory leak goes away, whereas the calls to ‘client.WriteItemValue’ stay identical to how they were before:
counter = 0
while True:
    time.sleep(15)
    values = []
    print(counter)
    for i in range(360):
        values.append(i + counter)
 
    for tag in tags:
        client.WriteItemValue('',opcserver,tag,values)
 
    counter = counter + 1

[...]

Best regards,
Z.
Last edit: 22 Nov 2017 15:48 by support.

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

More
22 Nov 2017 15:43 #5682 by support
From: C.
Sent: Monday, November 20, 2017 1:55 PM
To: Z.
Subject: RE: Potential Memory Leak?

Hi Z.,

I am using 2.7. I could test with 3 as well if you believe it could be version specific – just let me know what I can do to help.

Thank,
C.

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

More
22 Nov 2017 15:42 #5681 by support
From: Z.
Sent: Monday, November 20, 2017 5:11 AM
To: C.
Subject: RE: Potential Memory Leak?

C.,
Which Python version are you using please?

Thank you
Z.

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

More
22 Nov 2017 15:41 - 22 Nov 2017 15:47 #5680 by support
From: C.
Sent: Monday, November 13, 2017 1:20 PM
To: Z.
Subject: Potential Memory Leak?

Hi Z.,

[..] using QuickOPC in Python and [..] may have found a small memory leak that I wanted to get your input on. It seems to only happen when writing to arrays. If reading/writing to normal tags, there is no upward slope in memory. I was able to reproduce the growth here (seems to be about 1 MB an hour for me), so I wanted to send over a copy of the code and a sample TOP Server project to see if you can replicate this on your side. [...] using 2017.1 currently, but I did test with 2017.2 over the weekend and the behavior was still there for me.

The “[...]” python file is (very rough) code that just writes to two array tags on a 15 second interval. I used the “py2exe” library to compile the code into an executable – so that’s what the “setup.py”, “build” and “dist” folders are. If you open the “dist” folder, you can run the “[...].exe”.

I’ve included a sample TOP Server project as well and generated a temporary license (will be at the bottom of the email) for TOP Server (unfortunately this won’t with the “KEPServer” version) for you, since the [...] sample uses the “Advanced Simulator” driver in TOP Server – which requires a license to run longer than 2 hours at a time. [...], I’m using version 5.21 of TOP Server (you can download it here)

I still need to run some further tests on my side, but I wanted to get this into your hands to at least see if you could replicate the behavior I am seeing thus far. I do want to test with other OPC Servers to rule out it being a problem specifically with TOP Server as well.

Please let me know if there’s any other info I can provide, and I will keep you updated with my other tests as well.

Thank you in advance for the help,
C.
Attachments:
Last edit: 22 Nov 2017 15:47 by support.

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

Moderators: support
Time to create page: 0.183 seconds

      

 Recommend this on Google