引用计数
import sys a = [1, 2, 3] print(sys.getrefcount(a)) # 引用计数
弱引用
import weakref class Node: def __init__(self, value): self.value = value self.parent = None self.children = weakref.WeakSet()
垃圾回收
import gc # 手动触发垃圾回收 gc.collect() # 查看垃圾回收统计 print(gc.get_stats())
转载请注明:周志洋的博客 » Python进阶-内存管理