Show
Ignore:
Timestamp:
02/28/08 22:31:24 (21 months ago)
Author:
mpaschal
Message:

Add MT::Util::weaken() that lets us weaken references when available from a properly compiled Scalar::Util
Use weaken() to prevent some circular references from leaking some objects
(apply patches by Hirotaka Ogawa and Brad Choate--thanks!)
BugzID: 66845

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-30/lib/MT/Template.pm

    r1372 r1427  
    99use strict; 
    1010use base qw( MT::Object ); 
     11use MT::Util qw( weaken ); 
    1112 
    1213use constant NODE => 'MT::Template::Node'; 
     
    143144    require MT::Template::Context; 
    144145    my $ctx = $tmpl->{context} ||= MT::Template::Context->new; 
    145     $ctx->stash('template', $tmpl); 
     146    weaken($ctx->{__stash}{'template'} = $tmpl); 
    146147    return $ctx; 
    147148} 
     
    616617    my $tmpl = shift; 
    617618    my ($tag, $attr) = @_; 
    618     return bless [ $tag, $attr, undef, undef, undef, undef, $tmpl ], NODE; 
     619    my $node = bless [ $tag, $attr, undef, undef, undef, undef, $tmpl ], NODE; 
     620    weaken($node->[6]); 
     621    return $node; 
    619622} 
    620623 
     
    622625    my $tmpl = shift; 
    623626    my ($text) = @_; 
    624     return bless [ 'TEXT', $text, undef, undef, undef, undef, $tmpl ], NODE; 
     627    my $node = bless [ 'TEXT', $text, undef, undef, undef, undef, $tmpl ], NODE; 
     628    weaken($node->[6]); 
     629    return $node; 
    625630} 
    626631 
     
    740745 
    741746use strict; 
     747use MT::Util qw( weaken ); 
    742748 
    743749sub setAttribute { 
     
    823829    my $node = shift; 
    824830    $node->[5] = shift if @_; 
     831    weaken($node->[5]); 
    825832    $node->[5]; 
    826833}