Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Looking for Leaks

by dragonchild (Archbishop)
on Aug 09, 2001 at 20:11 UTC ( #103473=note: print w/replies, xml ) Need Help??


in reply to Looking for Leaks

I don't have any examples of techniques, and that's cause I'm curious as to how to generate memory leaks in Perl...

------
/me wants to be the brightest bulb in the chandelier!

Vote paco for President!

Replies are listed 'Best First'.
Re: Re: Looking for Leaks
by Hofmator (Curate) on Aug 09, 2001 at 20:19 UTC

    Memory leak version 0.1 :)

    my $var; $var = \$var;

    -- Hofmator

Re: Re: Looking for Leaks
by Corion (Patriarch) on Aug 09, 2001 at 20:22 UTC

    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 ;-)

Re: Re: Looking for Leaks
by Cirollo (Friar) on Aug 09, 2001 at 20:21 UTC
    I can't seem to find the post, but I remember somebody saying that it was possible to cause a memory leak by doing some strange stuff with references; if you can keep the reference count from being decremented to 0, the reference will never get destroyed even when it goes out of scope and viola; a memory leak.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2023-02-05 18:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (32 votes). Check out past polls.

    Notices?