Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

DESTROY Function call

by zeeshan1995 (Initiate)
on Jul 16, 2018 at 10:22 UTC ( #1218548=perlquestion: print w/replies, xml ) Need Help??

zeeshan1995 has asked for the wisdom of the Perl Monks concerning the following question:

Does perl guarantee that the  DESTROY() function will be called immediately after the closing braces } for the objects in the scope created using  new()( as C++ does)?

Replies are listed 'Best First'.
Re: DESTROY Function call
by Corion (Pope) on Jul 16, 2018 at 10:50 UTC

    No. The DESTROY function will be called immediately after the last reference to the object goes out of scope.

    This is fairly similar to what C++ seemingly does, but only in the case where no references escape that scope.

    See Scope::Guard, Guard and similar classes that use this mechanism to ensure cleanup of resources when a scope is left.

    Update: Also, the "SEE ALSO" section of Scope::Guard mentions many other modules that implement the same approach.

    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2020-11-24 01:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?