Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re (tilly) 1: $obj-DESTROY isn't called upon

by Sinister (Friar)
on Jan 31, 2002 at 13:32 UTC ( [id://142413]=note: print w/replies, xml ) Need Help??


in reply to Re (tilly) 1: $obj-DESTROY isn't called upon
in thread $obj-DESTROY isn't called upon

Hi tilly! Thnx for the post, but it is not running under mod_perl - I have actualy found the cause of the problem, after an intensive search through the cookbook. I found that when a perl script is instantiated using exec (or similar) DESTROY will never be called upon when the program exits.

Therefor I now advise in the POD to do a undef $obj; before the script exits. This seems to be the only way to have it run the DESTROY routine... Thanks for your quite usefull post anyway (I can very much use this for another project)...

Sinister greetings.
"With tying hashes you can do everything God and Larry have forbidden" -- Johan Vromans - YAPC::Europe 2001
perldoc -q $_

Replies are listed 'Best First'.
(tye)Re: $obj-DESTROY isn't called upon
by tye (Sage) on Jan 31, 2002 at 17:05 UTC

    Um, all instances of perl under Unix are instantiated using exec(). DESTROY doesn't get called if you script goes away because of a successful exec. How perl was started doesn't matter.

    Now, if the script isn't being run by perl (the separate executable) but is instead being run by a Perl interpretter embedded in some other executable, then your object might not be destroyed until the interpretter is torn down, and that might not happen until much later in such cases. mod_perl is just one example of this. You can usually check $^X to if you have such a case.

    If you avoid putting references to your object into global variables (also known as package variables), then your DESTROY method won't have to wait until the interpretter is destroyed. But inheritting from CGI would probably break that since CGI stores a reference to its first instantiation into a global variable in case you use the "function" interface (vs. of the OO interface).

            - tye (but my friends call me "Tye")
      >Um, all instances of perl under Unix are instantiated
      >using exec(). DESTROY doesn't get called if you script
      >goes away because of a successful exec. How perl was
      >started doesn't matter.
      That is not completely true. If you'd do `exec perl -e 'print "hello world\"'` on your shell, then the shell will be thrown away and be replaced with the perl interpreter. It wont return either...

      Sinister greetings.
      "With tying hashes you can do everything God and Larry have forbidden" -- Johan Vromans - YAPC::Europe 2001
      perldoc -q $_

        But that doesn't change whether DESTROY is called:

        $ perl -e "sub DESTROY{warn'dead'}\$x=bless{};" dead during global destruction. $ exec perl -e "sub DESTROY{warn'dead'}\$x=bless{};" dead during global destruction.

        BTW, in both of the cases above, perl is launched by using exec() [the subroutine from the C run-time library that wraps the kernel hook (or "system call")]. The difference is that the shell's "exec" command avoids the fork() before the exec().

                - 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://142413]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-25 17:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found