python-cx_Oracle
python-cx_Oracle copied to clipboard
Possible memory leak when using rowfactory
-
OracleDB version Oracle 11.2.1
-
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)
-
Is it an error or a hang or a crash? Hang because the system can run out of memory.
-
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.
-
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()]