News for hackers. Stuff that matters.
Re:Garbage Collection by lizmat on Sunday December 01, 2019 @08:02AM (#21675267)
Raku (née Perl 6) has phasers that will be called when exiting a scope. One such idiom is:

    {
        # do stuff
        my $dbh = DB.connect(...);
        # do stuff
        LEAVE .disconnect with $dbh;
        # do stuff
    }
Whenever the scope is left (this could be because of an execution error, or a `return`), the code of the LEAVE phaser will be executed. The `with $dbh` checks whether the $dbh variable contains an instantiated object. If so, it topicalizes (set $_ to it) and calls the disconnect method (`.disconnect` being short for `$_.disconnect`).

For more complex uses, and more tuneable finalizing, there is the `FINALIZER` module in the ecosystem: https://modules.raku.org/dist/FINALIZER

Re:Garbage Collection by smueller1234 on Sunday December 01, 2019 @08:49AM (#21675463)
Sure, but "schedule action at scope exit" is an easy (assuming your runtime already knows how to unwind the stacks) problem to solve. "Perform escape analysis and guarantee immediate destruction; efficiently without full gc nor refcounting" is not and they're not the same problem at all.