Skip to content
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

EmbeddedDocumentListField causes additional memory usage. #2820

Open
neolooong opened this issue Jun 20, 2024 · 0 comments · May be fixed by #2821
Open

EmbeddedDocumentListField causes additional memory usage. #2820

neolooong opened this issue Jun 20, 2024 · 0 comments · May be fixed by #2821

Comments

@neolooong
Copy link

This is the minimal example I found:

class Comment(EmbeddedDocument):
    content = StringField()

class Post(Document):
    title = StringField()
    comments = EmbeddedDocumentListField(Comment)

if Post.objects.count() == 0:
    for i in range(100):
        Post(title=f"{i}", comments=[Comment[f"{i}"]]).save()

def ok():
    qs = Post.objects
    for post in qs:
        post.title

def bug():
    qs = Post.objects
    for post in qs:
        post.comments

gc.collect()
ok()
print("collect after ok():", gc.collect())  # 0
bug()
print("collect after bug():", gc.collect())  # collect many objects

gc.collect() does not collect anything after exiting ok(). However, it can collect some objects after exiting bug().
The more times Post.comments accessed, the more memory used.
Although this may not a big problem since it can eventually collect internally by python.
In my case, this increase several gigabytes of RAM within a few minutes.

@neolooong neolooong linked a pull request Jun 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant