[Python-Dev] Memory management in the AST parser & compiler

Jeremy Hylton jeremy at alum.mit.edu
Mon Nov 28 21:47:07 CET 2005


On 11/28/05, Guido van Rossum <guido at python.org> wrote:
> On 11/18/05, Neil Schemenauer <nas at arctrix.com> wrote:
> > Perhaps we should use the memory management technique that the rest
> > of Python uses: reference counting.  I don't see why the AST
> > structures couldn't be PyObjects.
>
> Me neither. Adding yet another memory allocation scheme to Python's
> already staggering number of memory allocation strategies sounds like
> a bad idea.

The reason this thread started was the complaint that reference
counting in the compiler is really difficult.  Almost every line of
code can lead to an error exit.  The code becomes quite cluttered when
it uses reference counting.  Right now, the AST is created with
malloc/free, but that makes it hard to free the ast at the right time.
 It would be fairly complex to convert the ast nodes to pyobjects. 
They're just simple discriminated unions right now.  If they were
allocated from an arena, the entire arena could be freed when the
compilation pass ends.

Jeremy


More information about the Python-Dev mailing list