def mem(way=1):
print time()
for i in range(10000000):
if way == 1:
pass
else: # way 2, 3
del i
print time()
if way == 1 or way == 2:
pass
else: # way 3
gc.collect()
print time()
if __name__ == "__main__":
print "Test way 1: just pass"
mem(way=1)
sleep(20)
print "Test way 2: just del"
mem(way=2)
sleep(20)
print "Test way 3: del, and then gc.collect()"
mem(way=3)
sleep(20)
root@PCCW:~# free -m
total used free shared buff/cache available
Mem: 481 188 93 1 200 240
Swap: 1023 75 948
root@PCCW:~# python release.py
Test way 1: just pass
1525947171.8
1525947178.84
1525947178.84
Test way 2: just del
1525947198.87
1525947199.91
1525947199.91
Test way 3: del, and then gc.collect()
1525947219.93
1525947220.78
1525947221.44
root@PCCW:~# free -m
total used free shared buff/cache available
Mem: 481 100 310 0 71 330
Swap: 1023 162 861
root@PCCW:~#