efficient Python object count
lists at cheimes.de
Fri Nov 7 04:28:17 CET 2008
> Does anyone know of an efficient way to get a count of the total
> number of Python objects in CPython? The best solution I've been able
> to find is len(gc.get_objects()) which unfortunately has to walk a C
> linked list *and* creates a list containing all of the objects, when
> all I need is an object count.
There is no way to get correct numbers with a standard Python compiler.
You have to use a special debug build but that requires debug builds of
all extensions too.
gc.get_object() lists only object that are maintained by gc. Several
types don't use gc, for example str, unicode, int, float, long and more.
More information about the Python-list