greetings wise monks..
I have a program with an evil memory leak. It may caused by Text::Template Module,but I don't know how to get rid of it.

use Text::Template;
my $linehash={'a'=>'b','c'=>'d'...};
my $Template=Text::Template->new(TYPE=>'FILE',SOURCE=>'D:\sample.xml');
my $Text=$Template->fill_in(HASH=>$linehash);
# memory used increase 2000k,
undef $Template;
#the memory did not released

why?and how to resolved it?

thanks.

I Run PXPerl 5.8.7-6 at WindowsXP SP2,Table has 50000 recode,it cost 1000k every record.
This translate table's record to XML File.
#!perl -w
use strict;

use File::Basename;
use File::Spec;
use Data::Dump; 

use Text::Template;
use Win32::OLE;
use Adoscan;

my $SourceDataConnectionString;
$SourceDataConnectionString='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security
Info=False;Initial Catalog=GF_GG;Data Source=BEEB';
my $zc='select * from T_2001B0clcp';

#------------------ Main ----------------
print "Begin...at ".localtime()."\n";
# Begin to Convert SQL's Data to text file 
Db2Text(\&Action,$SourceDataConnectionString,$zc);
print "$zc Complete! at".localtime()."\n";

# Begin to transefer Data's index to web's database

}#---------------- End Main --------------

sub Db2Text
{
    my $Action=shift;
    my $DataConnectionString=shift;
    my $string=shift;
    
    # Cycle DataBase TABLE
    Adoscan::scandb($Action,$DataConnectionString,$string);
}

sub Action
{
    my $linehash=shift;
    if( ! $linehash )
    {
         print "Not Define Function! parameter is $linehash \n";
         return;
    }
    my $mark=GetTemplateFile($linehash);       
    my $Template=Text::Template->new(TYPE=>'FILE',SOURCE=>$mark);
my $Text=$Template->fill_in(HASH=>$linehash);
# Do other things
undef $Template;
    return;
}

File:Adoscan # It is my personal lib

package Adoscan;
use strict;
use Data::Dump;
use Win32::OLE::Lite;
use Win32::OLE;
use Win32::OLE::Const;

# despite you do noting,it cost 4k every cycle
sub scandb
{
	my $function=shift;
	my $oledbstring=shift;
	my $commandstring=shift;
	my $conn = Win32::OLE->new('ADODB.Connection'); 
	# my $RS = Win32::OLE->new('ADODB.Recordset');
	$conn->Open($oledbstring);
	if (Win32::OLE->LastError()){             
		print "This didn't go well: ", Win32::OLE->LastError(), "\n";
	}
	my $rst=$conn->Execute($commandstring); 
	if (Win32::OLE->LastError()){             
		print "This didn't go well: ", Win32::OLE->LastError(), "\n";
	}
    # my $rows=[];
	while(!($rst->{EOF}))
	{
		my $currentrow={};
        my $count = $rst->Fields->{Count};
        for(my $i=0;$i<$count;$i++)
	    {
            	my $columnname=$rst->Fields($i)->{Name};
			    my $columnvalue=$rst->Fields($i)->{Value};
			    if(defined($columnvalue))
		    	{
		    		$columnvalue=~s/^\s+//;
		    		$columnvalue=~s/\s+$//;
		    	}
		    	else
		    	{
		    		#$null||($columnvalue='');
		    	}
                $currentrow->{$columnname}=$columnvalue;
		}
		#push(@$rows,$currentrow);
		($debug eq '1')&&(print (caller().$currentrow."\n"));
		&$function($currentrow);
		$rst->MoveNext;
	}
	$conn->Close;
	#return $rows;
}

1;

#END

In reply to memory leak by camenix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.