package Release; use strict; use warnings; sub new { my $class = shift; my ($sub, @args) = @_; bless sub { sub { $sub->(@args) }; }, $class; } sub cancel { bless $_[0], 'ReleaseCancel'; } sub DESTROY { $_[0]->()->(); } package ReleaseCancel; sub DESTROY { 1 } package main; use strict; use warnings; my $n = 200; my $v = 'x' x 500_000; # THIS LEAKS 500K ON EVERY ITERATION in 5.6.1 and lower for (1..$n) { my $foo = Release->new(sub {my ($num, $msg) = @_; print "$num: Foo $msg\n"}, $_, "destroyed", $v); print "$_\n"; $foo->cancel if $_ == 2; print "Release foo\n"; my $p = scalar(); } print "Done\n";