5

I'm writing an OPC client so I use the Python OpenOPC library.

The problem is each time I'm reading a list of OPC items, my app consume memory.

For example, the following code consume 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
[]

The memory is released when I close the app.

So I don't understand why my app leaks memory and how avoid this.

Have you some ideas ? Thanks

Loïc G.
  • 3,087
  • 3
  • 24
  • 36
  • try without connection inside the loop – PepperoniPizza Oct 02 '13 at 14:39
  • How are you measuring the memory usage? – Robᵩ Oct 02 '13 at 23:10
  • 1
    OpenOPC looks like it is a Python extension, written in C (and/or Python). It seems to me the memory leak is on the C side, not in your code. Try explicitly deleting 'dataList' (`del dataList`) and 'res'. Make a bug report to the OpenOPC author. – mguijarr Oct 03 '13 at 00:44
  • I've tried to explicitly delete the `dataList` & `res` vars without change. The memory usage is measured by the Windows task manager. – Loïc G. Oct 03 '13 at 09:23

1 Answers1

3

Found a solution by 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()
Loïc G.
  • 3,087
  • 3
  • 24
  • 36