Python object has no references, but accessible via weakref?

Should gc.get_referrers (obj) return an empty list for an object, but the object is still accessible via a weak link?

If so, how will I start trying to determine the reason for this object that is not going to garbage?

Edit: I'm not sure exactly how the sample code will help in this case - there obviously is a strong link there, but I'll be damned if I can find it. I got the impression that all strong object references would be identified by get_referrers ().

Edit: Allowed . I found a variable with a strong reference - it was inside the game event loop, but it was not a class variable, so get_referrers did not collect it.

+3
source share
5 answers

Yes: http://docs.python.org/library/weakref.html

A weak link will not save the object.

The get_referrers () function will only detect containers that support garbage collection; extension types that relate to other objects but do not support garbage collection will not be found.

What makes you think that the object is not going to? Also, have you tried gc.collect ()?

+1
source

It is also possible that the link was skipped using the extended extension C, IMHO you will not see the referent, but refcount does not go to 0. You might also want to check the return value sys.getrefcount.

+1
source

, , . , , .

, , .

Python 2.7: " - , , , ".

NO-OP .

CPython ( )

+1

, , Python .

Python , __del__.
( ) ​​, gc.garbage.

0

Source: https://habr.com/ru/post/1712609/


All Articles