Advertisement
jsbueno

reference counting example

Apr 8th, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. >>>
  2. >>> class ListaQueAvisaQuandoMorre(list):
  3. ...     def __del__(self):
  4. ...         print(f"Lista com id {id(self)} destruida")
  5. ...        
  6. ...
  7. >>> a = ListaQueAvisaQuandoMorre([10, 20, 30])
  8. >>> del a
  9. Lista com id 140337716637024 destruida
  10. >>> a = ListaQueAvisaQuandoMorre([10, 20, 30])
  11. >>> gerad = (v for v in a)
  12. >>> del a
  13. >>> print(next(gerad))
  14. 10
  15. >>> print(next(gerad))
  16. 20
  17. >>> print(next(gerad))
  18. 30
  19. >>> print(next(gerad))
  20. Lista com id 140337716637024 destruida
  21. Traceback (most recent call last):
  22.   File "<stdin>", line 1, in <module>
  23. StopIteration
  24. >>> del gerad
  25. >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement