Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #4630

Re: Hooking into Python's memory management

From sturlamolden <sturla@molden.no>
Newsgroups comp.lang.python
Subject Re: Hooking into Python's memory management
Date 2011-05-04 10:11 -0700
Organization http://groups.google.com
Message-ID <7e324a8f-1eb8-4e4a-aa2c-f5ed741c7989@f2g2000yqf.googlegroups.com> (permalink)
References <mailman.1157.1304527910.9059.python-list@python.org>

Show all headers | View raw


On May 4, 6:51 pm, Daniel Neilson <ddneil...@gmail.com> wrote:

>   In either case, if such a module is possible, any pointers you could
> provide regarding how to implement such a module would be appreciated.


The gc module will hook into the garbage collector.

The del statement will remove an object from the current scope.
(Delete the variable name and decrement the reference count.)

Python (CPython that is) is reference counted. When the refcount drops
to zero, the object is immediately garbage collected. Python is not
like Java, where this happen in bouts. The __del__ method is executed
deterministically, it's not like a finalizer in Java or C#.

Only dead objects involved in reference circles may linger until they
are spotted by the GC. And they may not have a __del__ method, or else
the GC will ignore them.

In fact, if you don't create circular references, the GC can safely be
turned off.

If you want volatile references, Python allows weak references as
well.


Sturla



Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Hooking into Python's memory management Daniel Neilson <ddneilson@gmail.com> - 2011-05-04 10:51 -0600
  Re: Hooking into Python's memory management sturlamolden <sturla@molden.no> - 2011-05-04 10:11 -0700
  Re: Hooking into Python's memory management Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-05-05 15:16 +1200
  Re: Hooking into Python's memory management scattered <tooscattered@gmail.com> - 2011-05-04 21:06 -0700

csiph-web