7
不Python解释器会优雅的处理,其中一个对象实例删除最后一个引用自身的情况?对象删除引用自
考虑以下(当然没用)模块:
all_instances = []
class A(object):
def __init__(self):
global all_instances
all_instances.append(self)
def delete_me(self):
global all_instances
self.context = "I'm still here"
all_instances.remove(self)
print self.context
现在的用法:
import the_module
a = the_module.A()
the_deletion_func = a.delete_me
del a
the_deletion_func()
这仍然打印I'm still here
,但有使用Python的垃圾收集器的竞争条件是即将收集对象实例?
对对象功能的引用是否节省了一天的时间?
解释器是否保持对其当前正在执行代码的对象的引用,直到它完成?