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
to_builtins leaks the field objects of array_like=True structs (0.21.1) #1175
msgspec.to_builtins on a struct that contains an array_like=True struct never releases the field objects of the array-like struct: every call leaks them, even when the result is discarded. Converting through msgspec.json.decode(msgspec.json.encode(obj)) does not leak.
Environment: msgspec 0.21.1 (PyPI wheel), CPython 3.11, reproduced on Linux x86_64 and Windows 11.
Traced memory scales linearly with the number of to_builtins calls (about 4 floats × 24 B per call — the four fields of Box; tracemalloc attributes them to the decode line that created them). The JSON round-trip stays flat. Without array_like=True on Box there is no growth either, so it looks like a missing DECREF on the array-like path in to_builtins.
Found in a 24 h soak of a service that converted ~30 messages/s with to_builtins: RSS grew ≈ 50 MB/h until the call was replaced.
Activity
Fix reference leak in to_builtins for array-like Structs (msgspec#1177)