最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Why does sys.getrefcount() returns a huge number in circular reference? - Stack Overflow

programmeradmin0浏览0评论

I am trying to understand why reference counting technique of garbage collection cannot handle circular references. So I used this code to verify that the reference count doesn't go to zero.

import sys

# Function to count references to an object in the program
def count_references(obj):
    return sys.getrefcount(obj) - 1


# Example objects
l = []
l.append(l)

l = None

# Count references before deleting any reference
print("References to 'l' before deletion:", count_references(l))

this was the output

References to 'l' before deletion: 4413

I would be grateful if someone could explain the reference between these large numbers.

Thanks in advance.

发布评论

评论列表(0)

  1. 暂无评论