Mark and Sweep GC is triggered when many new **tracked** objects are
created and
not destroyed.

Since integer doesn't have reference to another objects, it's not tracked
object.
So your sample code doesn't show difference of GC.
You can see gc stats via gc.set_debug(gc.DEBUG_STATS).

Play this script with time command.

import gc


class Tree:
    def __init__(self, n):
        if n > 0:
            self.a = Tree(n-1)
            self.b = Tree(n-1)
        self.n = n


def main():
    #gc.set_debug(gc.DEBUG_STATS)
    #gc.disable()
    #gc.set_threshold(150000, 10, 10)
    for _ in range(10):
        Tree(16)


main()


On Sat, May 14, 2016 at 11:12 PM, Steven D'Aprano <st...@pearwood.info>
wrote:

> Just for kicks, I've been playing around with running code snippets with
> and
> without the garbage collector enabled, looking to see if it will make any
> obvious difference to performance.
>
> So far, I haven't found any.
>
> For instance, I tried:
>
> a = [i**3 for i in range(2000000)]
> del a[:]
>
> thinking that garbage collecting almost two million ints would surely show
> some performance difference, but it doesn't.
>
> Is anyone able to demonstrate a replicable performance impact due to
> garbage
> collection?
>
>
>
> --
> Steven
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
INADA Naoki  <songofaca...@gmail.com>
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to