Garbage collection

Tom Wright tew24 at
Wed Mar 21 18:25:35 CET 2007

skip at wrote:
> If your program's behavior is:
>     * allocate a list of 1e7 ints
>     * delete that list
> how does the Python interpreter know your next bit of execution won't be
> to repeat the allocation?

It doesn't know, but if the program runs for a while without repeating it,
it's a fair bet that it won't mind waiting the next time it does a big
allocation.  How long 'a while' is would obviously be open to debate.

> In addition, checking to see that an arena in 
> the free list can be freed is itself not a free operation.
> (snip thorough explanation)

Yes, that's a good point.  It looks like the list is designed for speedy
re-use of the memory it points to, which seems like a good choice.  I quite
agree that it should hang on to *some* memory, and perhaps my artificial
situation has shown this as a problem when it wouldn't cause any issues for
real programs.  I can't help thinking that there are some situations where
you need a lot of memory for a short time though, and it would be nice to
be able to use it briefly and then hand most of it back.  Still, I see the
practical difficulties with doing this.

I'm at CAMbridge, not SPAMbridge

More information about the Python-list mailing list