$ cat foo.py
class Foo:
def __del__(self):
print('freed', self)
def make():
for i in range(5):
yield Foo()
from sys import getrefcount as rc
for obj in make():
# refcount should == 2, one for `obj` binding and other for the argument
# binding in rc().
print(rc(obj))
$ python3 foo.py
2
freed <__main__.Foo object at 0x7f38b17b6a90>
2
freed <__main__.Foo object at 0x7f38b17b6b38>
2
freed <__main__.Foo object at 0x7f38b17b6a90>
2
freed <__main__.Foo object at 0x7f38b17b6b38>
2
freed <__main__.Foo object at 0x7f38b17b6a90>