[Python-Dev] refleaks and caches

Neal Norwitz nnorwitz at gmail.com
Mon Jan 28 01:35:35 CET 2008


On Jan 27, 2008 3:37 PM, Christian Heimes <lists at cheimes.de> wrote:
> Phillip J. Eby wrote:
> > Expose an API to clear the cache, and clear it at shutdown?  It
> > should probably be part of interpreter shutdown anyway.
>
> Good point. I've implemented PyType_ClearCache and exposed it via
> sys._cleartypecache(). The function is called during finalization, too.

I'm not sure we should expose an API to clear the cache, but I don't
have strong opinions either way.  If we keep the ability to clear the
cache, should we also consider some control over the int/float
freelist?  These are worse than the tuple/frame free lists since
int/floats are unbounded.  I suspect the method free lists in
Objects/methodobject.c and Objects/classobject.c don't have that many
entries that could be removed.

There may not be a lot we can do for the int/float caches and I'm not
sure if it's worth it.  We can't move objects once created, although
we could scan the blocks and if there are no live objects in a block,
free it.  That would presumably help with this case:

  list(range(some_big_number))

I don't know how important these things are in practice.

> Can somebody please double check the change? The results are promising
> and I'm sure I've implemented it correctly but you never know ;)

The biggest problem I have with the patch is the attribute name.  I
would prefer underscores.  ie _clear_type_cache instead of
_cleartypecache.  Attributes in sys are currently inconsistent, but it
seems that most of the newer names have underscores.  (Aside: if we
are going to move attrs out of sys for py3k, we should consider
renaming them to be consistent too.  Regardless of moving them, should
we rename them.)

n


More information about the Python-Dev mailing list