Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Building an object tree

by unixwzrd (Beadle)
on Feb 26, 2001 at 02:10 UTC ( [id://60786]=note: print w/replies, xml ) Need Help??


in reply to Building an object tree

You could get into trouble with memory leaks due to the garbage collection in Perl. It counts references to the variable and removes it when the count becomes zero.

For instance, you might have a child node that was the parent for two other nodes. If were not careful when deleting the child, the childres for which it is the parent might still be allocated memory, and they would be inaccessible.

I highly recommend Damian Conway's book "Object Oriented Perl". it goes into this subject quite well.

Mike - mps@discomsys.com

"The two most common elements in the universe are hydrogen... and stupidity."
Harlan Ellison

Replies are listed 'Best First'.
Re (tilly) 2: Building an object tree
by tilly (Archbishop) on Feb 26, 2001 at 02:19 UTC
    As long as parents point to children, but not vica versa, when the parent goes away, its children will have their counts decremented and they go away as well.

    The problem only comes if children keep track of their parents. For instance consider a directory tree. Each directory uses "." and ".." to keep track of itself and its parent. What this means is that when the last external reference to a directory tree goes away, the tree hangs around because it refers to itself.

    If you wish to get around this you will need to be using Perl 5.6.x or higher, and you will need to install the WeakRef module. (OK, there are other ways, but this one is the simplest.) Then weaken all of the links that cause recursion, and no more memory leaks!

      WeakRef looks great -- I've wanted something like this on several occasions. Unfortunately, it seems to require a patch to the Perl core. Any possibility of a weakening function becoming a standard part of Perl?
        I don't know what the plans are for it. I think that the idea of a module was to give people a chance to play with the API before they locked an interface down forever. OTOH Perl 6 looks like it is heading towards true garbage collection, so WeakRef is probably going to be filling a need no longer felt.
Re: Re: Building an object tree
by Beatnik (Parson) on Feb 26, 2001 at 02:19 UTC
    Thanks.
    I actually have the book (altho I should find more time to read it properly), and I believe it mentions the memory leak issue. The node level wont be as deep as it could get, since I realize loading objects in a tree can get quite resource consuming.

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-26 03:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found