Details
-
Bug
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
1.1.6
-
None
-
None
-
WIN10 and debian 11 bullseye
-
3.10.4
Description
I consider this to be bug. If you think otherwise, please treat it as a feature request or update documentation.
Steps to reproduce
- Run mariadb server (e.g. docker run -e MARIADB_ROOT_PASSWORD="<put_password_here>" -p 3306:3306 mariadb:10.6.11 )
- Repeat many times (see attached script)
- Create connection
- Get cursor
- Use cursor (cursor.execute(…), cursor.fetchone())
- Close connection
Expected outcome
Memory is freed when Cursor objects get garbage collected. The documentation does not tell, that cursor.close() must be called in order to avoid memory leaks. Also PEP-249 suggests, that calling cursor.close() is optional and that the garbage collector will eventually clean up resources:
Close the connection now (rather than whenever ._del_() is called).
Actual outcome
Output of attached script:
D:\source\mariadb_memory_leak\env\lib\site-packages\mariadb\cursors.py:208: size=1133 KiB (+1133 KiB), count=30000 (+30000), average=39 B
|
D:\source\mariadb_memory_leak\test.py:52: size=468 KiB (+468 KiB), count=9986 (+9986), average=48 B
|
D:\source\mariadb_memory_leak\env\lib\site-packages\mariadb\cursors.py:317: size=78.1 KiB (+78.1 KiB), count=10000 (+10000), average=8 B
|
Workaround
Call cursor.close() explicitly after using a cursor.