Skip to content

Instantly share code, notes, and snippets.

@tanchao90
Created February 9, 2017 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanchao90/f53c9e02deedc2d528122ee098b45c46 to your computer and use it in GitHub Desktop.
Save tanchao90/f53c9e02deedc2d528122ee098b45c46 to your computer and use it in GitHub Desktop.
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