1. import gc
  2.  
  3. class myObj:
  4.     a = []
  5.     b = False
  6.  
  7. global o
  8. o = myObj()
  9.  
  10. def test(name = False):
  11.     global o
  12.     if name: print("\nTesting after %s:" % name)
  13.     gc.collect()
  14.     o = myObj()
  15.     print(o.a)
  16.     print(o.b)
  17.  
  18. o.a.append(True)
  19. o.a.append(3.141)
  20. o.a.append("I'm still here!")
  21. o.b = True
  22.  
  23. print("\nInitial values:")
  24. test()
  25.  
  26. del o
  27. test('object deletion') # result: array populated
  28.  
  29. if 0:
  30.     del o.a # AttributeError: myObj instance has no attribute 'a'
  31.     del o
  32.     test('array deletion') # result: n/a
  33.  
  34. o.a = []
  35. test('array re-init') # result: array populated
  36.  
  37. for item in o.a:
  38.     del item
  39. test('array per-item deletion') # result: array populated
  40.  
  41.  
  42. while len(o.a):
  43.     o.a.pop()
  44. test('pop()') # result: array clear