[Tutor] how is memory de-allocated?
pythonTutor at venix.com
Sat Apr 10 21:21:36 EDT 2004
I should have pointed out that local names are deleted automatically
when a function or method completes executing. Those names "pass out of
scope". Objects that are no longer referenced (no longer accessible)
will be deleted and their memory reclaimed by the garbage collector. It
is seldom necessary to explicitly delete variables.
On Sat, 2004-04-10 at 15:26, Lloyd Kvam wrote:
> There is automatic garbage collection as in Java. IF we no longer need
> an object we can delete the name we use to refer to the object. If that
> was the last reference then the memory used by that object will be
> The example below creates a tuple and uses the name x to refer to that
> tuple. Once the name is deleted, the garbage collection will detect
> that the tuple can no longer be used and will reclaim the memory.
> >>> x = (1,2,3)
> >>> x
> (1, 2, 3)
> >>> del x
> >>> x
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> NameError: name 'x' is not defined
> On Sat, 2004-04-10 at 13:53, dlafrance at cs-linux.ubishops.ca wrote:
> > Hi,
> > I would like know how is memory de-allocated?
> > Through explicit programmer instruction like c++ or via garbage collection
> > like Java
> > And if it is possible can you give me an example
> > Thanks.
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
1 Court Street, Suite 378
Lebanon, NH 03766-1358
More information about the Tutor