Monday, March 23, 2015

gc.get_threshold() - Python Tutorial


gc.get_threshold()


gc.get_threshold() is a function that we can use when we import the garbage collection module. This function will return when the garbage collection algorithm will run to clean up the memory. The number that is returned to us is the threshold when the algorithm is ran.  


gc.get_threshold() Example


#gc.get_threshold()

>>> import gc
>>> gc.get_threshold()
(700, 10, 10)

 


gc.get_threshold(threshold0, threshold1, threshold2)


You will see three numbers returned to us and these numbers are set at three different runs of the garbage collection. First one is ran when the allocations minus the deallocations exceed the number displayed.Default for threshold0 is 700. If the object survives the first run it is relocated into the second run. The second number returned to us is when the second garbage collection will run this is threshold1 of garbage collection this number is based on the number runs that threshold0 does. The succeeding generation default is 10 so in this case threshold0 run must run ten times before the threshold1 of garbage collection is ran. If an object survives the subsequent run it is now moved into the third and final run and the object will stay here until it is removed. Threshold2 will run based off threshold1 runs.  The default is 10 threshold1 runs. So, when the threshold1 runs ten times the final generation will run.


 



No comments:

Post a Comment