Hi there,

  I'm having a problem with template toolkit Version 2.14, which appears
to have a memory leak when using custom filters.

  I'm running an Apache webserver (1.3.29) with mod perl (1.29).  When
running my webserver in single-user mode with the -X flag, and using 'ps
u -u httpd' to measure memory usage, the memory usage of my webserver
process increases by an amount proportional to the size of the template
file every time I process a template which the '[% USE my_filter %]
directive.  (I have code snippets further down if they would be
helpful).

  The TODO file on tt2.org contains the following:

  "The 'eval' filter leaks memory, as reported by Colin Johnson.  The
  filter subroutine created contains a reference to the context and then
  gets cached in the FILTER_CACHE item of the context.  Hey presto -
  circular references.  The reset() method should probably clear the
  FILTER_CACHE..."

  "...Also need to check the plugins cache for similar problems."

  Am I running into the same problem, expressed through the plugins cache?
 Does anyone have any suggestions or information on fixing or working
around this?  I couldn't find anything related to a reset() method - Is
this a suggested workaround, or a musing about a future fix?

  If it is helpful, here is the code I'm using to process the templates:

  test.cgi:
  -----------------------
  my $t = Template->new({
      INCLUDE_PATH => "Templates",
      PLUGIN_BASE  => "Eznettools::Filter::Template",
   });

   $t->process( 'test.ttml', {} ) ||
      say("Template processing failed: ".$t->error(), 1);
  -----------------------



  test.ttml:
  -----------------------
  [%- USE JScriptSafe -%]

  Template Processed!
  -----------------------
  (Note that I do not use the filter in this template, just including
   the filter causes the leak)



  JScriptSafe.pm: (I've removed most of the comments to keep the
                   size of this email down)
  -----------------------
  package Eznettools::Filter::Template::JScriptSafe;

  use strict;
  use Eznettools::Filter::HTML qw(make_jscript_safe);

  use base qw( Template::Plugin::Filter );

  sub init {
     my $self = shift;

     #    (Commented out to see if helped the memory leaks...it doesn't.)
     #
     #    my $name = $self->{ _ARGS }->[0] || 'ezjscript';
     #    $self->install_filter( $name );

     return $self;
  }

  sub filter {
     my ($self, $text) = @_;

     return make_jscript_safe( $text );
  }
  -----------------------

  I'd appreciate any suggestions/advice anyone could give.  I searched the
mailing list archives back to the release of TT 2.14 and didn't find
anything that looked related to this problem, sorry if it's already been
addressed.


-----------------------------------------
This email was sent using EZOnlineMail.
http://www.ezonlinemail.com/

_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to