Hello !
I recently began to play with Perl exception mechanisms, and gave a try to the Error module with the "try/catch" syntax.
However, reading docs (
Matt Sergeant presentation), I discovered that it presents a serious issue with regard to closures, and creates memory leaks.
But I also read in the
DDJ article from Dave Rolsky that Perl >= 5.8.4 might fix the closure issue ?
Trying the test sample provided in the presentation:
#!/usr/bin/perl -w
use strict;
use warnings;
use Error qw(:try);
for (1..3) {
my $x = Foo->new();
try {
try { print "$_: $x\n" };
};
}
END { warn("interpreter exit\n") }
package Foo;
sub new { return bless {}, shift }
sub DESTROY { warn("Foo::DESTROY\n") }
I indeed notice that the output result changes between perl 5.6.1:
1: Foo=HASH(0x80f6084)
2: Foo=HASH(0x813b750)
3: Foo=HASH(0x815a0f0)
interpreter exit
Foo::DESTROY
Foo::DESTROY
Foo::DESTROY
and Perl 5.10.0:
1: Foo=HASH(0x81981f8)
Foo::DESTROY
2: Foo=HASH(0x81981f8)
Foo::DESTROY
3: Foo=HASH(0x81981f8)
Foo::DESTROY
interpreter exit
The object seems indeed destroyed when leaving the loop's scope.
Can we then consider that this closure issue when using the "try/catch" syntax of the Error package is
over ? Is it now
advisable to use the Error module with the "try/catch" syntax ?
Nothing appears indeed in the perl584delta.pod about closures.
Regards,
Pierre
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.