python-cx_Oracle icon indicating copy to clipboard operation
python-cx_Oracle copied to clipboard

Possible memory leak when using rowfactory

Open robingie opened this issue 2 years ago • 0 comments

  1. OracleDB version Oracle 11.2.1

  2. Commands

  • print("sys.maxsize > 232:", sys.maxsize > 232) True
  • print("platform.platform:", platform.platform()) platform.platform: Linux-4.18.0-348.7.1.el8_5.x86_64-x86_64-with-glibc2.28
  • print("platform.python_version:", platform.python_version()) platform.python_version: 3.9.6
  • print("cx_Oracle.version:", cx_Oracle.version) cx_Oracle.version: 8.3.0
  • print("cx_Oracle.clientversion:", cx_Oracle.clientversion()) cx_Oracle.clientversion: (19, 6, 0, 0, 0)
  1. Is it an error or a hang or a crash? Hang because the system can run out of memory.

  2. What error(s) or behavior you are seeing? The Python application grows in memory size after a while. Each time a new cursor is created and the cursor.rowfactory is used, the memory requirement increases.

  3. Include a runnable Python script that shows the problem.

with conn.cursor() as cur:
        cur.execute(query2, start_id=start_id)

        # This line causes a growing memory footprint
        cur.rowfactory = lambda *args: dict(zip([d[0] for d in cur.description], args))

        # This line avoids the memory leak
        data = [dict((cur.description[i][0], value) for i, value in enumerate(row)) for row in cur.fetchall()]

image

robingie avatar May 02 '22 14:05 robingie