开发者

GC in python: what will this behave?

开发者 https://www.devze.com 2023-01-29 08:44 出处:网络
A python class A: a = A() array.append(a) ... some operation triggers a\'s method b() in a.b(): array.remove(self);

A python class A:

a = A()
array.append(a)

... some operation triggers a's method b()

in a.b():

array.remove(self);
# will开发者_运维技巧 this make the self be freed? as the only reference has been removed from array.
# access the a's data...


While the method is executing, you still have a reference(self) to a .

Only once the method completes is a eligible for collection.

0

精彩评论

暂无评论...
验证码 换一张
取 消