-
-
Notifications
You must be signed in to change notification settings - Fork 629
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
Memory leak? #1943
Comments
Here is a minimal repro: #! mprof run
from marshmallow import fields, Schema
class ArtistSchema(Schema):
name = fields.Str()
for _ in range(100000):
ArtistSchema().dumps({"name": "David Bowie"}) If you remove the field, the leak goes away. #! mprof run
from marshmallow import fields, Schema
class ArtistSchema(Schema):
pass
for _ in range(100000):
ArtistSchema().dumps({"name": "David Bowie"}) I suspect this is caused by circular references between the schema and the field. The schema has a list of fields. The field has a parent attribute. We would need to use a weakref proxy for the schema reference in the field to ensure that the tree unravels when the schema is ready to be released. |
I confirmed that The garbage collector is supposed to be able to detect circular references, but we are probably doing something dynamic that it can't infer. Clearing the circular references in |
I just ran the longer profile test on the dev branch and realized that the garbage collector does eventually cleanup these circular references on its own. I should have noticed that the memory usage leveled off around 3s in my very first test. I suspect the garbage collector has a strategy based on the percent of currently used memory. Everything appears to be working as intended. |
I'm using
marshmallow
with Falcon and have observed a quite strange memory leak. This minimal application does nothing but provide a GET endpoint serializing a dictionary and profiling the memory usage withmemory_profiler
:Sending now 100,000 requests like:
will slowly increase the memory footprint from 53.0 MiB to 54.5 MiB (and would apparently continue to increase like this).
I'm constructing a new
ArtistSchema
object for every request. But if I do this only once an reuse it for every request:the memory usage does not increase. How is this possible? Or is this even a
marshmallow
issue?My setup:
marshmallow
3.14.1falcon
3.0.1gunicorn
20.1.0memory-profiler
0.60.0The text was updated successfully, but these errors were encountered: