Skip to content

sqlite3 Connection maintains an unused list of weakrefs to Cursor objects #144377

Closed

Description

@takluyver

The sqlite3 Connection object creates a list to hold weakrefs to Cursors, and each cursor registers itself in that list when it's created.

PyObject *cursors = PyList_New(0);
if (cursors == NULL) {
Py_DECREF(statement_cache);
goto error;
}

register_cursor(pysqlite_Connection *connection, PyObject *cursor)
{
PyObject *weakref = PyWeakref_NewRef((PyObject *)cursor, NULL);
if (weakref == NULL) {
return 0;
}
if (PyList_Append(connection->cursors, weakref) < 0) {
Py_CLEAR(weakref);
return 0;
}
Py_DECREF(weakref);
return 1;
}

There's code to periodically clear out dead weakrefs from the list, but nothing I can see that actually uses it. It looks like the use was removed in #26026.

Linked PRs

Activity

  1. added a commit that references this issue on Feb 3, 2026
  2. added a commit that references this issue on Feb 3, 2026
  3. added a commit that references this issue on Feb 15, 2026
  4. erlend-aasland commented on Feb 27, 2026

    @erlend-aasland
    Contributor

    Thanks, @takluyver; happy to see this code go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions