Python Memory Manager

Steve Holden steve at holdenweb.com
Sun Feb 17 15:12:24 EST 2008


Paul Rubin wrote:
> Pie Squared <PieSquared at gmail.com> writes:
>> Also, if it does, how does it deal with memory segmentation? This
>> question bothers me because I've been trying to implement a moving
>> garbage collector, and am not sure how to deal with updating all
>> program pointers to objects on the heap, and thought perhaps an answer
>> to this question would give me some ideas. 
> 
> As I understand it, Python primarily uses reference counting, with a
> mark and sweep scheme for cycle breaking tacked on as an afterthought.
> It doesn't move objects in memory during GC so you can get
> fragmentation. It's probably not feasible to change this in CPython
> without extensive rewriting of CPython and maybe a lot of external C
> modules.
> 
>> (Also, if you know any
>> resources for things like this, I'd be grateful for links/names)
> 
> If you mean about GC in general, the old book by Jones and Lins is
> still standard, I think.

You also need to be aware that there are certain allocation classes 
which use arenas, areas of storage dedicated to specific object types. 
When those objects are destroyed their space is returned to the arena, 
but the arena is either never returned to the free pool or only returned 
to it when the last allocated item is collected.

There seem to be more of those kind of tricks coming up in 2.6 and 3.0.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list