Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

sqlite3 Blob objects leave behind weakrefs which are never cleaned up #144424

Copy link
Copy link
@takluyver

Description

@takluyver
Issue body actions

Bug report

Bug description:

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.

import gc
import sqlite3

conn = 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 objects
for _ in range(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 here
blob_list = gc.get_referents(conn)[-3]
print(len(blob_list))

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    Status
    No status
    Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.