Uploaded image for project: 'MariaDB Connector/Python'
  1. MariaDB Connector/Python
  2. CONPY-263

Memory leak if cursor.close() not called explicitly

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 1.1.6
    • None
    • Generic
    • 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

      1. Run mariadb server (e.g. docker run -e MARIADB_ROOT_PASSWORD="<put_password_here>" -p 3306:3306 mariadb:10.6.11 )
      2. Repeat many times (see attached script)
        1. Create connection
        2. Get cursor
        3. Use cursor (cursor.execute(…), cursor.fetchone())
        4. 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.

      Attachments

        Activity

          People

            georg Georg Richter
            gmech G.Mech
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.