【发布时间】:2021-01-09 19:55:13
【问题描述】:
如果我有
class MyClass:
def __init__(self, object):
self.object = object
some_other_object = SomeOtherObject()
myclass = MyClass(some_other_object)
del myclass
some_other_object 会发生什么?它也被删除了吗?
【问题讨论】:
-
还有一个对它的引用 -
some_other_object- 所以它仍然是那里。在 Python shell 中很容易尝试。 -
所以
del只删除myclass中它是唯一所有者的对象? -
正在寻找一个受骗的候选人,但这里有一些 值得深思的东西:Python memory management, Reference counting implementation detail 在文档的数据模型部分,... stackoverflow.com/a/16687693/2823755
标签: python