# HG changeset patch # User sergey # Date 1361366697 -14400 # Node ID 7b0dad6117d5e073494bab440276d471c662f6b5 # Parent 85572f512abc16593facde007087cb1d18a1d788 *TTView: fixed memory leak diff -r 85572f512abc -r 7b0dad6117d5 Lib/IMPL/Web/View/TTDocument.pm --- a/Lib/IMPL/Web/View/TTDocument.pm Wed Feb 20 02:25:30 2013 +0400 +++ b/Lib/IMPL/Web/View/TTDocument.pm Wed Feb 20 17:24:57 2013 +0400 @@ -48,14 +48,20 @@ my %controls; my $require; my $documentContext; + + my $self = $this; + $require = sub { my $control = shift; + + carp("Cant load control $control outside the rendering procedure") unless $self; + if (my $factory = $controls{$control}) { return $factory; } else { my $path = $control; - if ( my $template = $this->loader->template($path) ) { + if ( my $template = $self->loader->template($path) ) { $factory = new IMPL::Web::View::TTFactory( $template->class || TTControl, @@ -81,10 +87,9 @@ $this->context->localise(); $documentContext = _clone_context( $this->context ); - my $self = $this; - weaken($self); + $this->context->stash->set(require => $require); - #$this->context->stash->set(document => sub { $self }); + $this->context->stash->set(document => sub { $self }); my $text = eval { @@ -120,6 +125,7 @@ undef $require; undef $documentContext; undef %controls; + undef $self; $this->context->delocalise(); diff -r 85572f512abc -r 7b0dad6117d5 Lib/IMPL/Web/View/TTFactory.pm --- a/Lib/IMPL/Web/View/TTFactory.pm Wed Feb 20 02:25:30 2013 +0400 +++ b/Lib/IMPL/Web/View/TTFactory.pm Wed Feb 20 17:24:57 2013 +0400 @@ -56,6 +56,7 @@ my $stash = $ctx->stash; my $require = $this->require; + $stash->update({ require => sub { my ($module) = @_;