Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: Object reference disappearing during global destruction

by khkramer (Scribe)
on May 15, 2002 at 19:24 UTC ( #166823=note: print w/ replies, xml ) Need Help??


in reply to Re: Object reference disappearing during global destruction
in thread Object reference disappearing during global destruction

But the interpreter isn't cleaning up the object, it's setting the reference to undef. The object is still around (and accessible by other means).

I like your recreational-swim analogy, but I'm still trying to figure out how the behavior I'm seeing is consistent with the specified operation of the garbage collector. The Camel book says that objects are always destroyed in a separate pass before ordinary references (3rd ed. page 331), and maybe that's a clue, but there's still a problem:

When the interpreter is ready to exit, presumably "everything" goes out of scope. At that point, there are no references left to my $::index object. So it should be garbage collected pretty early. But it's not and, worse, an object reference it's holding is set to undef at some apparently arbritrary moment. I've been very careful to avoid circular references, so there *is* a sensible destruction order for these objects. But if references disappear without provocation, then that order can't be maintained.


Comment on Re: Re: Object reference disappearing during global destruction
Re: Re: Re: Object reference disappearing during global destruction
by chromatic (Archbishop) on May 15, 2002 at 20:54 UTC
    Maybe Elian will correct me if I'm completely wrong here, but reference counting isn't all that useful during global destruction. First, how do you figure out which items to collect first? Second, how do you deal with circular references? Third, if everything's going to be cleaned up anyway, does it matter? Fourth, it takes a lot longer to come up with a grand master plan than it does to pick a corner of the pool and start sweeping.

    As much as I'd like to believe that you can count on objects being destroyed, during global destruction, in normal, reference-counted order, I've never seen it happen. When it's mattered, I've always had to start the chain reaction myself.

Re: Re: Re: Object reference disappearing during global destruction
by erikharrison (Deacon) on May 16, 2002 at 04:34 UTC

    Let me give it a shot.

    First off, let me make sure I understand. You have a reference to an object, and you are dereferencing that ref in print statements, wondering whats going on, right?

    If you have a reference to an object, then the destruction of that reference will not invoke a call to a DESTROY method, only the objects actual destruction will. The objects destruction will occur in a pass before destruction of anything else. If you have a reference to an object, and the object is destroyed first (which it should be) the the reference points to nothing - undef. If the the scalar holding the reference to the object is itself undefed, and the object still exists, then this may be inconsistent with Perl's two pass out-of-the-pool system (where objects go first, so that their DESTROY methods can safely operate on variables in the environment). But, if you simply have a reference to the object, and you dereference that reference, then it should come up undef after global object destruction and before destruction of everything else.

    Hope that helps.

    Cheers,
    Erik

    Update: I just realized this is my 100th post. Yay!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2014-07-25 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls