Francois Gouget : testbot: Avoid reference cycles between Collections.
Alexandre Julliard
julliard at winehq.org
Thu Dec 21 07:24:24 CST 2017
Module: tools
Branch: master
Commit: 86aeeb298b68529e98c8bc44ae33d0db27898fbf
URL: http://source.winehq.org/git/tools.git/?a=commit;h=86aeeb298b68529e98c8bc44ae33d0db27898fbf
Author: Francois Gouget <fgouget at codeweavers.com>
Date: Thu Dec 21 12:14:21 2017 +0100
testbot: Avoid reference cycles between Collections.
Specifically when the Collection is used for a Detailref property (e.g.
Jobs->Steps), it should not keep a reference to the parent's ScopeItems.
Reference cycles cause Perl's primitive reference-count based garbage
collector to leak memory.
Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
testbot/lib/ObjectModel/Collection.pm | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/testbot/lib/ObjectModel/Collection.pm b/testbot/lib/ObjectModel/Collection.pm
index c3bc438..a9ec995 100644
--- a/testbot/lib/ObjectModel/Collection.pm
+++ b/testbot/lib/ObjectModel/Collection.pm
@@ -43,6 +43,7 @@ require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(&new &ComputeMasterKey);
+use Scalar::Util qw(weaken);
use ObjectModel::BackEnd;
use ObjectModel::Item;
use ObjectModel::PropertyDescriptor;
@@ -96,6 +97,14 @@ sub new($$$$$;$$@)
Filters => {},
AllScopeItems => $AllScopeItems || {},
Items => undef};
+ if ($AllScopeItems)
+ {
+ # Avoid memory cycles in case Items have Detailref properties:
+ # ParentCollection{AllScopeItems} --> ParentItem
+ # ParentItem --DetailrefProperty--> DetailCollection
+ # DetailCollection{AllScopeItems} == ParentCollection{AllScopeItems}
+ weaken($self->{AllScopeItems});
+ }
$self = bless $self, $class;
$self->_initialize(@_);
return $self;
More information about the wine-cvs
mailing list