Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
python gc回收测试,gc.get_count() 函数实验
import gc
gc.set_threshold(500, 10, 10)
class ClassA(object):
pass
print gc.get_count()
gc.collect()
print gc.get_count()
l = []
for x in xrange(1,70000):
a = ClassA()
l.append(a)
print gc.get_count()
del l
print gc.get_count()
# 程序运行结果
# 返回GC当前的运行情况
# (0, 0, 0)
# (4, 0, 0)
# (5, 0, 0)
# ...
# (499, 0, 0)
# (500, 0, 0)
# (0, 1, 0)
# (1, 1, 0)
# ...
# (500, 1, 0)
# (0, 2, 0)
# ...
# (500, 11, 0)
# (0, 0, 1)
# (1, 0, 1)
# ...
# (500, 0, 1)
# (0, 1, 1)
# (1, 1, 1)
# ...
# (500, 11, 10)
# (0, 0, 11)
# (1, 0, 11)
# ...
# (500, 0, 11)
# (1, 0, 0)
# (3, 0, 0)
# ...
# (365, 6, 0)
# (0, 6, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.