Skip to content

Commit 28f2cf5

Browse files
committed
BUG: Do not keep a ProgressAccumulator as a member of its mini-pipeline filter
ProgressAccumulator::SetMiniPipelineFilter() holds a SmartPointer, so a member accumulator pointed at its owner formed a reference cycle and LesionSegmentationMethod and FeatureAggregator were never destroyed. The leaked PoolMultiThreader kept the global ThreadPool alive past the teardown of its globals, so a pool thread that started late read a null ThreadPoolGlobals at exit and crashed intermittently. Create the accumulator in the call that uses it, as the other filters do.
1 parent 4b97058 commit 28f2cf5

4 files changed

Lines changed: 15 additions & 19 deletions

File tree

‎include/itkFeatureAggregator.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ class ITK_TEMPLATE_EXPORT FeatureAggregator : public FeatureGenerator<NDimension
102102
const InputFeatureType *
103103
GetInputFeature(unsigned int featureId) const;
104104

105-
ProgressAccumulator::Pointer m_ProgressAccumulator;
106-
107105
private:
108106
using FeatureGeneratorPointer = typename FeatureGeneratorType::Pointer;
109107
using FeatureGeneratorArrayType = std::vector<FeatureGeneratorPointer>;

‎include/itkFeatureAggregator.hxx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ FeatureAggregator<NDimension>::FeatureAggregator()
3636
typename OutputImageSpatialObjectType::Pointer outputObject = OutputImageSpatialObjectType::New();
3737

3838
this->ProcessObject::SetNthOutput(0, outputObject.GetPointer());
39-
40-
this->m_ProgressAccumulator = ProgressAccumulator::New();
41-
this->m_ProgressAccumulator->SetMiniPipelineFilter(this);
4239
}
4340

4441

@@ -143,14 +140,17 @@ template <unsigned int NDimension>
143140
void
144141
FeatureAggregator<NDimension>::UpdateAllFeatureGenerators()
145142
{
143+
ProgressAccumulator::Pointer progress = ProgressAccumulator::New();
144+
progress->SetMiniPipelineFilter(this);
145+
146146
auto gitr = this->m_FeatureGenerators.begin();
147147
auto gend = this->m_FeatureGenerators.end();
148148

149149
while (gitr != gend)
150150
{
151151
// Assuming that most of the time is spent in generating the features and
152152
// hardly negligible time is spent in consolidating the features
153-
this->m_ProgressAccumulator->RegisterInternalFilter(*gitr, 1.0 / this->m_FeatureGenerators.size());
153+
progress->RegisterInternalFilter(*gitr, 1.0 / this->m_FeatureGenerators.size());
154154

155155
(*gitr)->Update();
156156
++gitr;

‎include/itkLesionSegmentationMethod.h‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,10 @@ class ITK_TEMPLATE_EXPORT LesionSegmentationMethod : public ProcessObject
125125

126126
SegmentationModulePointer m_SegmentationModule;
127127

128-
ProgressAccumulator::Pointer m_ProgressAccumulator;
129-
130128

131129
/** This method calls the Update() method of each one of the feature generators */
132130
void
133-
UpdateAllFeatureGenerators();
131+
UpdateAllFeatureGenerators(ProgressAccumulator * progress);
134132

135133
/** This method compares the number of available features against the number
136134
* of expected features, and it will throw an exception if they do not match.
@@ -143,7 +141,7 @@ class ITK_TEMPLATE_EXPORT LesionSegmentationMethod : public ProcessObject
143141
ConnectFeaturesToSegmentationModule();
144142

145143
void
146-
ExecuteSegmentationModule();
144+
ExecuteSegmentationModule(ProgressAccumulator * progress);
147145
};
148146

149147
} // end namespace itk

‎include/itkLesionSegmentationMethod.hxx‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ LesionSegmentationMethod<NDimension>::LesionSegmentationMethod()
4242
typename OutputSpatialObjectType::Pointer outputObject = OutputSpatialObjectType::New();
4343

4444
this->ProcessObject::SetNthOutput(0, outputObject.GetPointer());
45-
46-
this->m_ProgressAccumulator = ProgressAccumulator::New();
47-
this->m_ProgressAccumulator->SetMiniPipelineFilter(this);
4845
}
4946

5047

@@ -105,13 +102,16 @@ LesionSegmentationMethod<NDimension>::GenerateData()
105102
itkExceptionMacro("Segmentation Module has not been connected");
106103
}
107104

108-
this->UpdateAllFeatureGenerators();
105+
ProgressAccumulator::Pointer progress = ProgressAccumulator::New();
106+
progress->SetMiniPipelineFilter(this);
107+
108+
this->UpdateAllFeatureGenerators(progress);
109109

110110
this->VerifyNumberOfAvailableFeaturesMatchedExpectations();
111111

112112
this->ConnectFeaturesToSegmentationModule();
113113

114-
this->ExecuteSegmentationModule();
114+
this->ExecuteSegmentationModule(progress);
115115
}
116116

117117

@@ -120,14 +120,14 @@ LesionSegmentationMethod<NDimension>::GenerateData()
120120
*/
121121
template <unsigned int NDimension>
122122
void
123-
LesionSegmentationMethod<NDimension>::UpdateAllFeatureGenerators()
123+
LesionSegmentationMethod<NDimension>::UpdateAllFeatureGenerators(ProgressAccumulator * progress)
124124
{
125125
auto gitr = this->m_FeatureGenerators.begin();
126126
auto gend = this->m_FeatureGenerators.end();
127127

128128
while (gitr != gend)
129129
{
130-
this->m_ProgressAccumulator->RegisterInternalFilter(*gitr, 0.5 / this->m_FeatureGenerators.size());
130+
progress->RegisterInternalFilter(*gitr, 0.5 / this->m_FeatureGenerators.size());
131131
(*gitr)->Update();
132132
++gitr;
133133
}
@@ -164,9 +164,9 @@ LesionSegmentationMethod<NDimension>::ConnectFeaturesToSegmentationModule()
164164

165165
template <unsigned int NDimension>
166166
void
167-
LesionSegmentationMethod<NDimension>::ExecuteSegmentationModule()
167+
LesionSegmentationMethod<NDimension>::ExecuteSegmentationModule(ProgressAccumulator * progress)
168168
{
169-
this->m_ProgressAccumulator->RegisterInternalFilter(this->m_SegmentationModule, 0.5);
169+
progress->RegisterInternalFilter(this->m_SegmentationModule, 0.5);
170170
this->m_SegmentationModule->SetInput(this->m_InitialSegmentation);
171171
this->m_SegmentationModule->Update();
172172
}

0 commit comments

Comments
 (0)