Closed luk2302 closed 7 months ago
Hi, I came across this issue because our software has a memory leak in production. After days of troubleshooting and narrowing down the problem, I came across this ticket.
Are there any plans to fix this in the near future? And how can it be that such a critical bug remains unfixed for 2 years?
I understand your frustration, but please refrain from "how can it be", when referring to free and open source software. Instead, you can offer time or money to free software projects to unblock situations like this.
This is (mostly) fixed by #258 (marshmallow_dataclass >= 8.6.1).
When necessary, references to frames are still held until the schema is constructed (by accessing the .Schema
attribute). Memory leakage is still possible if large numbers of marshmallow_dataclasses
are constructed without accessing their .Schema
attribute.
In https://github.com/lovasoa/marshmallow_dataclass/pull/187 a change was implemented that included the current stack frame in an internal cache, therefore causing all local variables of the entire call stack to never be freed. Demo:
No
__del__
is called on eitherSample
orOuter
during the method invocations, only after thecache_clear
can the local variables be garbage collected. If you run the demo with 8.4.4 or just replace_internal_class_schema(clazz, base_schema, clazz_frame)
with_internal_class_schema(clazz, base_schema, None)
in marshmallow_dataclass.class_schema. Additionally this also demonstrates that the caching does no longer work as there no cache hits at all anymore.