Created
February 9, 2017 08:31
-
-
Save tanchao90/f53c9e02deedc2d528122ee098b45c46 to your computer and use it in GitHub Desktop.
python gc回收测试,gc.get_count() 函数实验
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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