[Tutor] question about removing items from a list

dman dsh8290@rit.edu
Wed, 15 Aug 2001 10:33:58 -0400

On Wed, Aug 15, 2001 at 09:51:15AM -0400, Lance E Sloan wrote:
| "Allan Crooks" wrote:
| > An even better way would be like this:
| > 
| > del lista[:]
| > 
| > That would delete all items within the list. Doing 'del lista' would 
| > simply delete the list itself.
| What about:
|   lista = []
| That would give the intended effect, but I wonder what happens to the
| original list that lista pointed to.  Does it hang around in memory,
| or does Python's garbage collection get rid of it as soon as nothing
| points to it any longer?

It depends -- does any other binding refer to it?  If not then it will
be gc'd sooner or later.  CPython happens to release it sooner (based
on ref counting) but Jython must wait until the Java gc gets around to
freeing the objects.

The proper techinque (of the 3 given above) depends on what your
intent is.