deleting objects present in a list

Terry Reedy tjreedy at udel.edu
Tue Apr 20 21:44:32 CEST 2010


On 4/20/2010 3:21 PM, Sandy wrote:
> Hi all,
> I have large number of objects created and to handle them properly, I
> store them in a list. How can I delete all of these objects (delete I
> mean here is to remove the object from memory not just from list)?
> I cannot use the list to iterate through the objects to delete them.
> Because 'del' only reduces the reference count and as it is present in
> the list it is not deleted. I cannot delete the list because I loose
> control over the objects.

Deleting the list is the best you can do. If that deletes the last 
reference, then the interpreter will delete the object when it feels 
like it. For *current* CPython, this will be immediately. For other 
implementations, whenever.





More information about the Python-list mailing list