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? #276

Closed
andreymal opened this Issue Jun 29, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@andreymal

andreymal commented Jun 29, 2017

(I tried to reproduce this for few months and today I did it >_<)

import gc
from datetime import datetime

from pony.orm import * 

db = Database()

class Author(db.Entity):
    comments = Set('Comment')

class Post(db.Entity):
    pass

class Comment(db.Entity):
    author = Required(Author)

db.bind('sqlite', ':memory:')
db.generate_mapping(create_tables=True)

# prepare data

print('fill database...')
with db_session:
    a = Author(id=1)
    for i in range(2, 5000):
        Author(id=i)
        Post(id=i)
        Comment(author=a)
    del a

# test it!

@db_session
def testme():
    author = Author.get(id=15)
    comments_list = Comment.select(lambda x: x.author.id == author.id)
    ids = list(select(x.id for x in Post))

print('started')
while True:
    testme()
    gc.collect()

If you run it, then memory of python process will leak (+8MB per second on my machine).

Very strange things that prevented me from reproducing it:

  • If you append author_id = author.id and replace == author.id with == author_id, then everything is fine.
  • OR if you just comment/delete line ids = ..., then everything is fine too!

WTF?

@kozlovsky kozlovsky added the bug label Jul 15, 2017

@kozlovsky kozlovsky self-assigned this Jul 15, 2017

@kozlovsky

This comment has been minimized.

Show comment
Hide comment
@kozlovsky

kozlovsky Jul 15, 2017

Member

This is very interesting, thank you for reporting! I'll investigate that...

Member

kozlovsky commented Jul 15, 2017

This is very interesting, thank you for reporting! I'll investigate that...

@kozlovsky kozlovsky closed this in 6495daa Jul 17, 2017

@kozlovsky

This comment has been minimized.

Show comment
Hide comment
@kozlovsky

kozlovsky Jul 17, 2017

Member

We fixed memory leak, thank you very much! The fix will be included in PonyORM release 0.7.2

Member

kozlovsky commented Jul 17, 2017

We fixed memory leak, thank you very much! The fix will be included in PonyORM release 0.7.2

@kozlovsky kozlovsky added this to the 0.7.2 milestone Jul 17, 2017

kozlovsky added a commit that referenced this issue Jul 17, 2017

Pony ORM Release 0.7.2 (2017-07-17)
# New features

* All arguments of db.bind() can be specified as keyword arguments. Previously Pony required the first positional argument which specified the database provider. Now you can pass all the database parameters using the dict: db.bind(**db_params). See https://docs.ponyorm.com/api_reference.html#Database.bind
* The `optimistic` attribute option is added https://docs.ponyorm.com/api_reference.html#cmdoption-arg-optimistic

# Bugfixes

* Fixes #219: when a database driver raises an error, sometimes this error was masked by the 'RollbackException: InterfaceError: connection already closed' exception. This happened because on error, Pony tried to rollback transaction, but the connection to the database was already closed and it masked the initial error. Now Pony displays the original error which helps to understand the cause of the problem.
* Fixes #276: Memory leak
* Fixes the __all__ declaration. Previously IDEs, such as PyCharm, could not understand what is going to be imported by 'from pony.orm import *'. Now it works fine.
* Fixes #232: negate check for numeric expressions now checks if value is zero or NULL
* Fixes #238, fixes #133: raise TransactionIntegrityError exception instead of AssertionError if obj.collection.create(**kwargs) creates a duplicate object
* Fixes #221: issue with unicode json path keys
* Fixes bug when discriminator column is used as a part of a primary key
* Handle situation when SQLite blob column contains non-binary value

buttles added a commit to workstep/pony that referenced this issue Jun 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment