diff --git a/lib/HTML/Mason/Request.pm b/lib/HTML/Mason/Request.pm
index a8997cd5..886646ba 100644
--- a/lib/HTML/Mason/Request.pm
+++ b/lib/HTML/Mason/Request.pm
@@ -943,6 +943,7 @@ sub call_dynamic {
if (!defined($comp->dynamic_subs_request) or $comp->dynamic_subs_request ne $m) {
$comp->dynamic_subs_init;
$comp->dynamic_subs_request($m);
+ Scalar::Util::weaken( $comp->{dynamic_subs_request} ) if can_weaken;
}
return $comp->run_dynamic_sub($key, @args);
diff --git a/t/26-leak-with-shared.t b/t/26-leak-with-shared.t
new file mode 100644
index 00000000..b0a8abb8
--- /dev/null
+++ b/t/26-leak-with-shared.t
@@ -0,0 +1,47 @@
+use strict;
+use warnings;
+
+use HTML::Mason::Tools qw(can_weaken);
+BEGIN
+{
+ unless ( can_weaken )
+ {
+ print "Your installation does not include Scalar::Util::weaken\n";
+ print "1..0\n";
+ exit;
+ }
+}
+
+use Test::More;
+
+use HTML::Mason::Interp;
+
+plan tests => 2;
+
+our $Destroyed = 0;
+
+SIMPLE_OBJECTS:
+{
+ $Destroyed = 0;
+ my $interp = HTML::Mason::Interp->new( out_method => sub {} );
+ my $comp = $interp->make_component( comp_source => 'Comp' );
+ $interp->exec( $comp, Object->new() );
+ is( $Destroyed, 1, 'object passed into request was destroyed' );
+}
+
+SIMPLE_OBJECTS_WITH_SHARED:
+{
+ $Destroyed = 0;
+ my $interp = HTML::Mason::Interp->new( out_method => sub {} );
+ my $comp = $interp->make_component( comp_source => 'Comp<%shared>%shared>' );
+ $interp->exec( $comp, Object->new() );
+ is( $Destroyed, 1, 'object passed into request was destroyed with shared' );
+}
+
+package Object;
+
+sub new { return bless {}, $_[0] }
+
+sub DESTROY { $Destroyed++ }
+
+sub DestroyCount { $Destroyed }