memory recycling/garbage collecting problem

Steve Holden steve at
Thu Feb 26 11:30:41 EST 2009

David Niergarth wrote:
> Tim Peters showed a way to demonstrate the fix in
>> For simpler fun, run this silly little program, and look at memory
>> consumption at the prompts:
>> """
>> x = []
>> for i in xrange(1000000):
>>    x.append([])
>> raw_input("full ")
>> del x[:]
>> raw_input("empty ")
>> """
>> For example, in a release build on WinXP, VM size is about 48MB at the
>> "full" prompt, and drops to 3MB at the "empty" prompt.  In the trunk
>> (without this patch), VM size falls relatively little from what it is
>> at the "full" prompt (the contiguous vector holding a million
>> PyObject* pointers is freed, but the obmalloc arenas holding a
>> million+1 list objects are never freed).
>> For more info about the patch, see Evan's slides from _last_ year's PyCon:
> I'm not sure what deleting a slice accomplishes (del x[:]); the
> behavior is the same whether I do del x or del x[:]. Any ideas?
del x removes the name x from the current namespace, garbage collecting
the object to which it referred. del x[:] leaves x referencing a cleared

Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC    

More information about the Python-list mailing list