有没有办法在 Python 中获取对象的当前引用计数? [英] Is there a way to get the current ref count of an object in Python?
本文介绍了有没有办法在 Python 中获取对象的当前引用计数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在 Python 中获取对象的当前引用计数?
Is there a way to get the current ref count of an object in Python?
推荐答案
根据 Python 文档,sys
模块包含一个函数:
According to the Python documentation, the sys
module contains a function:
import sys
sys.getrefcount(object) #-- Returns the reference count of the object.
通常比您预期的高 1,因为对象 arg 临时引用.
Generally 1 higher than you might expect, because of object arg temp reference.
这篇关于有没有办法在 Python 中获取对象的当前引用计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文