You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

py-gc.py 271 B

123456789101112131415
  1. import gc
  2. class FooClass:
  3. def __init__(self):
  4. self.value = 1
  5. def __del__(self):
  6. print(f"FooClass {id(self)} destroyed!")
  7. foo1 = FooClass()
  8. foo2 = foo1
  9. del foo1
  10. print("Called del foo1")
  11. gc.collect()
  12. foo2.value += 1
  13. print("Called foo2.value += 1")