0

I want to a method that runs when object reference count is changed. is there a method like the following code ?

class Foo():
    def __method__(self):
        print("ojbect reference count is changed !")

a = Foo()
b = a  # runs __method__ because the reference count is increased
c = b  # runs __method__ because the reference count is increased
del b  # runs __method__ because the reference count is decreased
del c  # runs __method__ because the reference count is decreased

thanks.

Adam Smith
  • 52,157
  • 12
  • 73
  • 112
Nomad
  • 918
  • 6
  • 23
  • Possible duplicate of [Is there a way to get the current ref count of an object in Python?](https://stackoverflow.com/questions/510406/is-there-a-way-to-get-the-current-ref-count-of-an-object-in-python) – pvg Nov 12 '17 at 21:24
  • ^ It isn't really one though – cs95 Nov 12 '17 at 21:29
  • 2
    and how do you intend to use such function if there is one ? what is the problem you trying to solve ? – hchandad Nov 12 '17 at 21:34
  • @fins, I want to delete an object when reference count number of it changed to one or two or any other number. – Nomad Nov 12 '17 at 21:36
  • wanting to delete an object once it's reference count change. any python object or a specific one ? – hchandad Nov 12 '17 at 21:49

0 Answers0