-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Massive memory leak since 8.5.5 / leaking the entire stack frame and all local variables everywhere #198
Comments
Hi, Are there any plans to fix this in the near future? |
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. |
* Test for memory leaks as described in #198 * Possible fix for #198: memory leak * Optimization: avoid holding frame reference when locals == globals * Get caller frame at decoration-time Here we are more careful about which caller's locals we use to resolve forward type references. We want the callers locals at decoration-time — not at decorator-construction time. Consider: ```py frozen_dataclass = marshmallow_dataclass.dataclass(frozen=True) def f(): @custom_dataclass class A: b: "B" @custom_dataclass class B: x: int ``` The locals we want in this case are the one from where the custom_dataclass decorator is called, not from where marshmallow_dataclass.dataclass is called. * Add ability to pass explicit localns (and globalns) to class_schema When class_schema is called, it doesn't need the caller's whole stack frame. What it really wants is a `localns` to pass to `typing.get_type_hints` to be used to resolve type references. Here we add the ability to pass an explicit `localns` parameter to `class_schema`. We also add the ability to pass an explicit `globalns`, because ... might as well — it might come in useful. (Since we need these only to pass to `get_type_hints`, we might as well match `get_type_hints` API as closely as possible.) * test: check for frame leakage when decorators throw exceptions * Fix mypy by setting python to the minimum supported version, 3.8 --------- Co-authored-by: Jeff Dairiki <dairiki@dairiki.org>
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 |
In #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.The text was updated successfully, but these errors were encountered: