gc.setthreshold()?

Martin von Loewis loewis at informatik.hu-berlin.de
Wed Apr 18 07:29:52 EDT 2001


Jay Collins <jcollin at exis.net> writes:

> I was wondering if anyone has any tips for using gc.setthreshold()?  

My tip: don't call it.

> I added :
> 
> gc.enable()
> gc.set_debug(gc.DEBUG_STATS)
> gc.set_threshold(1,2,3)
> 
> to one of my programs and I got all kinds of neato output that I have no
> idea what it does. heheh

When running your program, you should watch how often garbage
collection is invoked, how many objects get collected, and how many
objects survive collection. If collection only collects a few objects,
with many objects being kept alive, it occurs too frequently. If each
collection frees a tremendous amount of objects, it probably occurs
too rarely. Then you might consider tuning it.

> anyways, how would you figure out what to put in gc.set_threshold()?

One reasonable setting is to set it to 0, which disables
collection. Another good setting is 1, which performs collection after
every new object: that finds cycles ASAP, at a high cost. Apart from
that, I doubt you'ld ever want to tune it.

Regards,
Martin



More information about the Python-list mailing list