SPUG: Question for somebody -- Releasing memory

Daniel Pommert dpommert at bestnet.com
Thu Nov 2 16:15:12 CST 2000


As stated by everyone else, normally, when the last reference to an object
is eliminated, the object is destroyed and the memory is released to the
memory pool.

There are some gotchya, however:
1) As mentioned above, sometimes the Perl system, itself has a memory leak.
This is rare, is usually minor is size, and can usually be discounted.
2) Reference cycles can cause objects to never be considered to be
"free-able".  I wrote a routine (which I don't have on me at my present
site) that will take a reference and trace down all of the accessible
references looking for reference cycles.  You would put it in your package's
DESTROY method and give it your $this or $self reference.  It would tell you
if that object contained or referred indirectly to something that had a
reference cycle.  It is a recursive (set of) routine written in Perl.  Its
deficiency is that it can't peer into closures.

Another way that you could find where you might have a memory leak is to get
your program to voluntarily cease execution and then use the caller function
in your package's DESTROY method.  If (I think) caller(1) says that it was
called "during global destruction" then that object is being freed during
Mark and Sweep phase of garbage collection.  This means that that object was
involved in a reference cycle and is (probably) garbage while the program is
running.  

When I was working on a large server program, I encountered some of these
"DESTROYed during global destruction" situations that I was unable to clean
up.  I did use closures quite a bit and am suspicious that that may have
been the source of my problem.

I'll see if I can bring in the cycle finder routine and post it to this
group.

Daniel Pommert
BEST Consulting
(at) AT&T Wireless Systems

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list