以下の動作がわかりません。
locals()
新しい参照はどのように発生しますか?- gc.collect で削除されないのはなぜですか?
locals()
私はどこにも結果を割り当てませんでした。
バツ
import gc
from sys import getrefcount
def trivial(x): return x
def demo(x):
print getrefcount(x)
x = trivial(x)
print getrefcount(x)
locals()
print getrefcount(x)
gc.collect()
print getrefcount(x)
demo(object())
出力は次のとおりです。
$ python demo.py
3
3
4
4