From 9513a8f851970d62b3f278a850e0357ae47c5f26 Mon Sep 17 00:00:00 2001 From: Graham McVicker <mcvicker@sanger.ac.uk> Date: Mon, 26 Jul 2004 11:03:43 +0000 Subject: [PATCH] fixed elusive memory leak: key space of parallel hash grew indefinately (one key per query performed). Should have used delete function rather than setting to undef. --- modules/Bio/EnsEMBL/DBSQL/StatementHandle.pm | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/Bio/EnsEMBL/DBSQL/StatementHandle.pm b/modules/Bio/EnsEMBL/DBSQL/StatementHandle.pm index 790e483fed..41632ada5d 100644 --- a/modules/Bio/EnsEMBL/DBSQL/StatementHandle.pm +++ b/modules/Bio/EnsEMBL/DBSQL/StatementHandle.pm @@ -32,6 +32,8 @@ use Bio::EnsEMBL::Utils::Exception qw(warning); use DBD::mysql; use DBI; +use Time::HiRes qw(time); + @ISA = qw(DBI::st); # As DBD::mysql::st is a tied hash can't store things in it, @@ -42,7 +44,13 @@ sub dbc { my $self = shift; if (@_) { - $dbchash{$self} = shift; + my $dbc = shift; + if(!defined($dbc)) { + # without delete key space would grow indefinately causing mem-leak + delete($dbchash{$self}); + } else { + $dbchash{$self} = $dbc; + } } return $dbchash{$self}; @@ -52,7 +60,13 @@ sub sql { my $self = shift; if (@_) { - $dbc_sql_hash{$self} = shift; + my $sql = shift; + if(!defined($sql)) { + # without delete key space would grow indefinately causing mem-leak + delete($dbc_sql_hash{$self}); + } else { + $dbc_sql_hash{$self} = $sql; + } } return $dbc_sql_hash{$self}; -- GitLab