Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Re: Looking for Leaks

by Corion (Patriarch)
on Aug 09, 2001 at 20:22 UTC ( [id://103478]=note: print w/replies, xml ) Need Help??

in reply to Re: Looking for Leaks
in thread Looking for Leaks

Since Perl still uses a reference count based garbage collector, creating memory leaks is quite easy. You just need to construct something with a reference count above 0 for all elements :

use strict; my @a; a[0] = \a;

In this (contrived) case, the reference count of a can't sink below 1, since a itself holds a reference to a.

Of course, in this trivial example, it's easy to find the memory leak, but if you have a single linked list, it's easy to create a circular structure that will never be reaped.

One way to overcome this would be to use another style of garbage collection, like a mark-and-sweep collector, that starts with a single "good" pointer, and recursively traces all memory reachable from there, and deallocates all memory unreachable from there. This obviously will create some interesting situations for when destructors will be called, but that's another story then ;-)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://103478]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2024-04-25 11:14 GMT
Find Nodes?
    Voting Booth?

    No recent polls found