card: fix memory leak from nested function scoping (#33328)

* stash

* no other leaks! pm.send grows memory usage by ~20mb but that's it

* undo

* clean up
pull/33329/head
Shane Smiskol 9 months ago committed by GitHub
parent 08f64ae30a
commit ee9977df2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 19
      selfdrive/car/card.py

@ -66,15 +66,7 @@ def is_dataclass(obj):
return hasattr(obj, _FIELDS) return hasattr(obj, _FIELDS)
def asdictref(obj) -> dict[str, Any]: def _asdictref_inner(obj) -> dict[str, Any] | Any:
"""
Similar to dataclasses.asdict without recursive type checking and copy.deepcopy
Note that the resulting dict will contain references to the original struct as a result
"""
if not is_dataclass(obj):
raise TypeError("asdictref() should be called on dataclass instances")
def _asdictref_inner(obj) -> dict[str, Any] | Any:
if is_dataclass(obj): if is_dataclass(obj):
ret = {} ret = {}
for field in getattr(obj, _FIELDS): # similar to dataclasses.fields() for field in getattr(obj, _FIELDS): # similar to dataclasses.fields()
@ -85,6 +77,15 @@ def asdictref(obj) -> dict[str, Any]:
else: else:
return obj return obj
def asdictref(obj) -> dict[str, Any]:
"""
Similar to dataclasses.asdict without recursive type checking and copy.deepcopy
Note that the resulting dict will contain references to the original struct as a result
"""
if not is_dataclass(obj):
raise TypeError("asdictref() should be called on dataclass instances")
return _asdictref_inner(obj) return _asdictref_inner(obj)

Loading…
Cancel
Save