[Bioperl-guts-l] [14788] bioperl-live/trunk/Bio/Assembly: Used weak references (Scalar::Util ::weaken) in a circular reference to fix memory leak
Florent E Angly
fangly at dev.open-bio.org
Tue Aug 5 18:48:06 EDT 2008
Revision: 14788
Author: fangly
Date: 2008-08-05 18:48:06 -0400 (Tue, 05 Aug 2008)
Log Message:
-----------
Used weak references (Scalar::Util::weaken) in a circular reference to fix memory leak
Modified Paths:
--------------
bioperl-live/trunk/Bio/Assembly/Contig.pm
bioperl-live/trunk/Bio/Assembly/Scaffold.pm
Modified: bioperl-live/trunk/Bio/Assembly/Contig.pm
===================================================================
--- bioperl-live/trunk/Bio/Assembly/Contig.pm 2008-08-05 22:07:49 UTC (rev 14787)
+++ bioperl-live/trunk/Bio/Assembly/Contig.pm 2008-08-05 22:48:06 UTC (rev 14788)
@@ -210,6 +210,8 @@
use Bio::SeqFeature::Collection;
use Bio::Seq::PrimaryQual;
+use Scalar::Util qw(weaken);
+
use base qw(Bio::Root::Root Bio::Align::AlignI);
=head1 Object creator
@@ -304,8 +306,11 @@
$self->throw("Using non Bio::Assembly::Scaffold object when assign contig to assembly")
if (defined $assembly && ! $assembly->isa("Bio::Assembly::Scaffold"));
+ # We create a circular reference to a Scaffold object. It is made weak
+ # to prevent memory leaks.
+ $self->{'_assembly'} = $assembly if (defined $assembly);
+ weaken($self->{'_assembly'});
- $self->{'_assembly'} = $assembly if (defined $assembly);
return $self->{'_assembly'};
}
@@ -2105,4 +2110,5 @@
return scalar(@{$dbref});
}
+
1;
Modified: bioperl-live/trunk/Bio/Assembly/Scaffold.pm
===================================================================
--- bioperl-live/trunk/Bio/Assembly/Scaffold.pm 2008-08-05 22:07:49 UTC (rev 14787)
+++ bioperl-live/trunk/Bio/Assembly/Scaffold.pm 2008-08-05 22:48:06 UTC (rev 14788)
@@ -65,7 +65,6 @@
package Bio::Assembly::Scaffold;
use strict;
-
use Bio::Annotation::Collection;
use base qw(Bio::Root::Root Bio::Assembly::ScaffoldI);
@@ -398,7 +397,7 @@
$self->warn("Replacing contig $contigID with a new contig object")
if (exists $self->{'_contigs'}{$contigID});
$self->{'_contigs'}{$contigID} = $contig;
- $contig->assembly($self);
+ $contig->assembly($self); # weak circular reference
# Put contig sequences in the list of sequences belonging to the scaffold
foreach my $seqID ($contig->get_seq_ids()) {
@@ -443,7 +442,7 @@
$self->warn("Replacing singlet $singletID with a new singlet object")
if (exists $self->{'_singlets'}{$singletID});
$self->{'_singlets'}{$singletID} = $singlet;
- $singlet->assembly($self);
+ $singlet->assembly($self); # weak circular reference
# Put singlet sequence in the list of sequences belonging to the scaffold
my $seqID = $singlet->seqref()->id();
@@ -686,4 +685,5 @@
return @singlets;
}
+
1;
More information about the Bioperl-guts-l
mailing list