2

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.

6
  • Possible duplicate of Is there a way to get the current ref count of an object in Python? Commented Nov 12, 2017 at 21:24
  • ^ It isn't really one though Commented Nov 12, 2017 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 ? Commented Nov 12, 2017 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. Commented Nov 12, 2017 at 21:36
  • wanting to delete an object once it's reference count change. any python object or a specific one ? Commented Nov 12, 2017 at 21:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.