Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

(tye)Re: non-deterministic destructors?

by tye (Sage)
on Nov 10, 2001 at 00:18 UTC ( [id://124463]=note: print w/replies, xml ) Need Help??


in reply to non-deterministic destructors?

Globals ("package variables") get destroyed in a "random" order. Keep all of your objects in lexicals and this problem should go away. Though a module putting objects into globals would also be a problem. (This has been discussed here before. If anyone finds the previous threads, then post a note here and I'll do the same if I get around to searching.)

        - tye (but my friends call me "Tye")
  • Comment on (tye)Re: non-deterministic destructors?

Replies are listed 'Best First'.
Re: (tye)Re: non-deterministic destructors?
by mikeB (Friar) on Nov 10, 2001 at 00:33 UTC
    The object is being created as
    my $table = new ExcelTable(...);
    I try to avoid globals :)

      Yes, but if anyone holds a reference to that same object in a global or in something that is referenced by something that is referenced by something... that is in a global, then destruction will be delayed until the ominously named "global destruction phase", at which point objects are destroyed in a "random" order.

      For example, closures aren't cleaned up until "the end" (even if you no longer hold a reference to them since Perl itself creates a references loop when it creates closures -- this bug has been fixed but I don't think the fix is in a stable release of Perl yet). Or perhaps ExcelTable keeps a list of objects that it has created.

      You could use Devel::Peek to see the reference count of what $table refers to. That would give you a hint if something else is keeping a reference to it (or perhaps you have an XS bug that is leaving the reference count on the other object too low so that it actually is getting destroyed early, tho that seems unlikely -- such XS bugs usually leave the ref count too high, which could be another reason why destruction of your main object is delayed).

              - tye (but my friends call me "Tye")

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 07:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found