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的垃圾收集器的競爭條件是即將收集對象實例?
對對象功能的引用是否節省了一天的時間?
解釋器是否保持對其當前正在執行代碼的對象的引用,直到它完成?