-
Notifications
You must be signed in to change notification settings - Fork 18
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
Severe memory leak #222
Comments
@asrenzo Hi, Thanks for the reporting! From a brief investigation It seems to me like that is a bug in I was able to reproduced the identical behavior in pure >>> import gc
...
... import objgraph
... import pydantic as pd
...
...
... class Company(pd.BaseModel):
... country: str
...
... @pd.field_validator("country")
... @classmethod
... def validate_country(cls, value: str) -> str:
... if len(value) > 2:
... raise ValueError("country must be of 2 characters")
... return value
...
...
... def create_company():
... err = None
... try:
... return Company.model_validate({'country': 'USA'}, strict=False)
... except pd.ValidationError as e:
... err = e
...
... raise err
...
...
... for _ in range(10000):
... try:
... company = create_company()
... except pd.ValidationError as e:
... company = None
...
... gc.collect()
... print(objgraph.show_most_common_types())
...
traceback 50000
frame 30002
ValueError 10000
ValidationError 10000
function 5142
tuple 3141
dict 2695
ReferenceType 1395
wrapper_descriptor 1330
method_descriptor 1183 It looks like the error traceback leaks when You get |
Hi, Thx for this quick answer. Problem is also on model_valiidator. What is thé next step? Shall we fill in an issue on pydantic or will you relay it? Regards |
…t rid of potential memory leak. See #222.
@canardoFR I made a fix in 2.14.0 that get rid of keeping I think I need more time to find out the origin of the problem before opening an issue on |
Will test, but can't before tuesday, sorry |
version 2.14.0 did the trick. No more memory leakage problems. Thanks a lot. |
Hi,
With latest version (2.13.1) of pydantic-xml we experience a severe memory leak. This problem may also be present with previous versions.
We were able to build a minimal working example to reproduce the problem which seems to be linked with field decorators and/or model_validators in children models of a main one.
Here is a simple way to vizualize the leak with objgraph.
Sounds like XmlElement, State and XmlEntityInfo are not cleaned when a model is loaded with invalid datasets
This example is based on your own documentation sample.
Don't know if you already are aware of this problem. Didn't find anything in open tickets.
Regards,
Laurent
The text was updated successfully, but these errors were encountered: