hello gregg,
Sunday, June 29, 2003, 11:09:20 PM, Вы писали:
g> This is just a guess, but I would try moving the "my $j" outside of the
g> for loop. This way you're quoting the same $j each time which instead
g> of creating a new one and then relying on "undef" to free up the
g> memory. I'm fairly new to Perl so I might not know what I'm talking
g> about, but I'm very experienced in C++, which has numerous memory
g> management issues I've struggled with.
g> Good Luck,
g> Gregg Allen
This code generate memory leak too:
#!/usr/local/bin/perl -w
use strict;
use DBI;
my $dbh = DBI->connect($data_source, $username, $password)
my $i;
my $j;
for ($i=1;$i<=100000000;$i++){
# memory leak is here
$j=$dbh->quote("JDXHFGURSEFUDSkrde");
# in $dbh->quote()
}
undef $j;
undef $i;
$dbh->disconnect();
undef $dbh;
I work under win2000 sp2
DBI VERSION=1,32,0,0
This is quote() function from DBI.pm:
sub quote {
my ($dbh, $str, $data_type) = @_;
return "NULL" unless defined $str;
unless ($data_type) {
$str =~ s/'/''/g; # ISO SQL2
return "'$str'"; # <-- memory leak is here, return "'".$str."'"; better
}
my $dbi_literal_quote_cache = $dbh->{'dbi_literal_quote_cache'} ||= [ {} , {}
];
my ($prefixes, $suffixes) = @$dbi_literal_quote_cache;
my $lp = $prefixes->{$data_type};
my $ls = $suffixes->{$data_type};
if ( ! defined $lp || ! defined $ls ) {
my $ti = $dbh->type_info($data_type);
$lp = $prefixes->{$data_type} = $ti ? $ti->{LITERAL_PREFIX} || "" : "'";
$ls = $suffixes->{$data_type} = $ti ? $ti->{LITERAL_SUFFIX} || "" : "'";
}
return $str unless $lp || $ls; # no quoting required
# XXX don't know what the standard says about escaping
# in the 'general case' (where $lp != "'").
# So we just do this and hope:
$str =~ s/$lp/$lp$lp/g
if $lp && $lp eq $ls && ($lp eq "'" || $lp eq '"');
return "$lp$str$ls"; # <-- memory leak is here, return $lp.$str.ls; better
}
sorry for my english.
С уважением,
Монашёв Михаил, SoftSearch.ru
ICQ# 166233339
http://softsearch.ru/
Без бэкапа по жизни.