Why is my memory leak application? How to avoid memory leak?

I am writing an OPC client, so I use the OpenOPC Python library.

The problem is that every time I read the list of OPC items, my application consumes memory.

For example, the following code consumes about 100ko at each iteration:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import OpenOPC
import time
import gc

gc.set_debug(gc.DEBUG_LEAK)

client = OpenOPC.client()
while True:
    client.connect('CODESYS.OPC.DA')
    dataList = client.list("PLC2.Application.GVL.*")
    res = client.read(dataList)
    client.close()
    print gc.collect()
    print gc.garbage

    time.sleep(2)

and the garbage collector returns:

0
[]

Memory is freed when you close the application.

So, I do not understand why my application is leaking memory and how to avoid this.

Do you have any ideas? Thanks

+4
source share
1 answer

Found a solution using the group argument of the read () function:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import OpenOPC

client = OpenOPC.client()
client.connect('CODESYS.OPC.DA')
tags = client.list("PLC2.Application.GVL.*")
while True:
    res = client.read(tags, group='MyGroup')
client.close()
+2
source

All Articles