RussBaz / enforce

Python 3.5+ runtime type checking for integration testing and data validation
543 stars 21 forks source link

@runtime_validation leaks refcounts and therefore causes memory leaks #74

Open itamarst opened 5 years ago

itamarst commented 5 years ago

Enforce 0.3.4.

import sys
from typing import List
import enforce

@enforce.runtime_validation
def noop_validated(i: List) -> List:
    return i

def noop(i: List) -> List:
    return i

if __name__ == '__main__':
    mylist = []
    print("Initial refcounts", sys.getrefcount(mylist))
    noop(mylist)
    print("Refcounts after noop():", sys.getrefcount(mylist))
    noop_validated(mylist)
    print("Refcounts after noop_validated():", sys.getrefcount(mylist))

Results:

$ python /tmp/reproducer.py 
Initial refcounts 2
Refcounts after noop(): 2
Refcounts after noop_validated(): 6