changeset 290:7b0dad6117d5

*TTView: fixed memory leak
author sergey
date Wed, 20 Feb 2013 17:24:57 +0400
parents 85572f512abc
children 5d14baa35790
files Lib/IMPL/Web/View/TTDocument.pm Lib/IMPL/Web/View/TTFactory.pm
diffstat 2 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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();
     
     
--- 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) = @_;