You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sqlite3 Blob objects leave behind weakrefs which are never cleaned up #144424
The sqlite3 Blob class registers a weakref to itself on the Connection it came from. These are added to a list and never cleaned up, so if you have a long-lived connection and call .blobopen() repeatedly, you gradually accumulate ever more dead weakrefs.
It looks like the blob weakrefs were added to match a similar system for weakrefs (removed in #144378), but the code to periodically clear out dead weakrefs was missed.
importgcimportsqlite3conn=sqlite3.connect(":memory:")
conn.execute("CREATE TABLE foo(a INTEGER PRIMARY KEY, b BLOB)")
conn.execute("INSERT INTO foo VALUES(NULL, ?)", (b'abcdefpokpokpko',))
conn.commit()
# Create & destroy many Blob objectsfor_inrange(10_000):
conn.blobopen("foo", "b", 1)
# Get a reference to the internal list of blob weakrefs - you may need to play with the index hereblob_list=gc.get_referents(conn)[-3]
print(len(blob_list))
This issue is that the weakrefs themselves are not cleaned up, so if you repeatedly access blobs on a long-lived connection, the list of weakrefs grows indefinitely. It's not questioning whether those weakrefs are used. #144435 is my attempt to fix this.
Activity
vstinner commentedon Feb 5, 2026
What is the purpose of this list of blob weak references? It seems to be unused. Why not just removing it instead?vstinner commentedon Feb 5, 2026
Ah! It's used by
pysqlite_close_all_blobs()function which is called by_sqlite3.Connection.close(). The function was added by the commit ee47543.erlend-aasland commentedon Mar 4, 2026
The list of blob weakrefs is used to close blobs on connection exit. Seems to me we can close this issue?
takluyver commentedon Mar 4, 2026
This issue is that the weakrefs themselves are not cleaned up, so if you repeatedly access blobs on a long-lived connection, the list of weakrefs grows indefinitely. It's not questioning whether those weakrefs are used. #144435 is my attempt to fix this.