[Beginner] delete items of [] also from memory

Steve Holden steve at holdenweb.com
Mon Nov 22 08:50:52 EST 2004


Birgit Rahm wrote:

>> But...  And if you try ?
>>
> 
> I tryed A = [].
> And  I think thats why my RAM is filling up. But I dont know if this is the
> problem. So I asked.
> Is del A[0:] the better or an equal solution?
> Birgit
> 
The two solutions are pretty much equal, the only (insignificant) 
difference being that a new empty list is created when you use A = [].

In either case the memory occupied by the elements of the list will all 
become available for garbage collection, and hence for the creation of 
new Python objects.

It will *not*, however, be returned to the operating system, so your 
process's memory footprint will remain at the high water mark set when 
you were using maximum memory for referenced objects.

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



More information about the Python-list mailing list