There is gc.get_referrers() and sys.getrefcount() . But, it is hard to understand how sys.getrefcount(X) can serve the purpose of traditional reference counting. Consider:
import sys def function(X): sub_function(X) def sub_function(X): sub_sub_function(X) def sub_sub_function(X): print sys.getrefcount(X)
Then function(SomeObject) supplies "7",
sub_function(SomeObject) supplies "5",
sub_sub_function(SomeObject) supplies "3" and
sys.getrefcount(SomeObject) supplies '2'.
In other words: if you use sys.getrefcount() , you must know the depth of the function call. For gc.get_referrers() may need to filter the list of referrers.
I would suggest doing manual reference counting for purposes such as isolation when changing, i.e. "clone if referenced elsewhere."
Frank-Rene SchΓ€fer Dec 10 '16 at 23:00 2016-12-10 23:00
source share