# How to \_really\_ disconnect pipeline?

**URL:** <https://discourse.itk.org/t/how-to-really-disconnect-pipeline/551>\
**Category:** Beginner Questions\
**Created:** [December 24, 2017, 3:13pm UTC](https://discourse.itk.org/t/how-to-really-disconnect-pipeline/551 "2017-12-24T15:13:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaspermarstal](https://discourse.itk.org/user_avatar/discourse.itk.org/kaspermarstal/32/211_2.png) [@kaspermarstal](https://discourse.itk.org/u/kaspermarstal)\
**Post date:** [December 24, 2017, 3:13pm UTC](https://discourse.itk.org/t/how-to-really-disconnect-pipeline/551/1 "2017-12-24T15:13:06Z")

</div>

Hello,

I am generating images in a loop and adding to multi-input filter. In pseudo-code

```
for(;;) {
  filterA = A::New()
  /* Do something with filterA, e.g. set a filename and read an image() */
  filterB = B::New()
  filterB->SetInput(filterA->GetOutput())
  filterB->Update()
  image = filterB->GetOutput()
  image->DisconnectPipeline()
  filterC->PushBackInput(image)
} 

filterC->Update()

```

However, I get a segfault when updating filterC because this update is propagated to the upstream of the disconnected input object: The disconnected inputs’ m\_Source still points the filterB (which has now gone out of scope) _after_ the call to DisconnectPipeline. This is because DisconnectPipeline only calls m\_Source-\>SetOutput(NULLPTR) on the input object, but the m\_Source itself is not set to null. Therefore, when UpdateOutputInformation() tries to propagate information to the source (which has now gone out of scope) the segfault occurs.

I could move filterB out of the loop to avoid that it goes out of scope. But that doesnt solve the underlying problem: The disconnected input is still connected to filterB via it’s m\_Source and update calls are propagated upstream.

Clearly there is something I have overlooked. I dont understand why any downstream updates should be propagated the upstream of a disconnected object (the way DisconnectPipeline is implemented).

To solve this particular use case, I need to set m\_Source on the input to nullptr (what I previously thought DisconnectPipeline did). How do I achieve this?

Thanks in advance and merry christmas!

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [December 24, 2017, 5:26pm UTC](https://discourse.itk.org/t/how-to-really-disconnect-pipeline/551/2 "2017-12-24T17:26:41Z")

</div>

Hello @kaspermarstal,

> [@kaspermarstal](#):
>
> input = filterB-\>Update()  
> input-\>DisconnectPipeline()  
> filterC-\>PushBackInput(image)

Here, is

```auto
filterB->Update();
ImageType:::Pointer output = filterB->GetOutput();
// PushBackInput internally uses a SmartPointer to increase the image's reference count
filterC->PushBackInput(output);

```

intended?

Merry Christmas! 🎄

---

<div class="post-metadata">

**Author:** ![kaspermarstal](https://discourse.itk.org/user_avatar/discourse.itk.org/kaspermarstal/32/211_2.png) [@kaspermarstal](https://discourse.itk.org/u/kaspermarstal)\
**Post date:** [December 26, 2017, 2:00pm UTC](https://discourse.itk.org/t/how-to-really-disconnect-pipeline/551/3 "2017-12-26T14:00:27Z")

</div>

Yes, thank you. Updated question 🙂

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [December 28, 2017, 3:33pm UTC](https://discourse.itk.org/t/how-to-really-disconnect-pipeline/551/4 "2017-12-28T15:33:34Z")

</div>

The described behavior does seem odd.

A minimal, compilable example source code will help determine specifically what is happening.

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [December 28, 2017, 3:42pm UTC](https://discourse.itk.org/t/how-to-really-disconnect-pipeline/551/5 "2017-12-28T15:42:38Z")

</div>

Because you name the results (or “output”): “input”, are you trying to use a circular pipeline?

I complete minimal example is needed, as Matt said. It’s likely that in the process of narrowing and isolating the problematic scenario you will determine the problem.

---

<div class="post-metadata">

**Author:** ![kaspermarstal](https://discourse.itk.org/user_avatar/discourse.itk.org/kaspermarstal/32/211_2.png) [@kaspermarstal](https://discourse.itk.org/u/kaspermarstal)\
**Post date:** [December 30, 2017, 12:40pm UTC](https://discourse.itk.org/t/how-to-really-disconnect-pipeline/551/6 "2017-12-30T12:40:12Z")

</div>

@blowekamp Not trying a circular pipeline no. I updated the pseudocode and will make a minimal example.

@matt.mccormick What is it that you find odd? That m\_Source is not nullptr after call to DisconnectPipeline? If not, what is the expected behaviour?

Thanks for your input!

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [January 5, 2018, 4:03pm UTC](https://discourse.itk.org/t/how-to-really-disconnect-pipeline/551/7 "2018-01-05T16:03:31Z")

</div>

> [@kaspermarstal](#):
>
> @matt.mccormick What is it that you find odd? That m\_Source is not nullptr after call to DisconnectPipeline? If not, what is the expected behaviour?

In any case, there should not be a segfault. But, the pseudo-code does not look correct. A runnable example should help.

---

<div class="post-metadata">

**Author:** ![millerjv](https://discourse.itk.org/user_avatar/discourse.itk.org/millerjv/32/176_2.png) [@millerjv](https://discourse.itk.org/u/millerjv)\
**Post date:** [January 30, 2018, 12:56pm UTC](https://discourse.itk.org/t/how-to-really-disconnect-pipeline/551/8 "2018-01-30T12:56:48Z")

</div>

A call to DisconnectPipeline() triggers a set of calls to return the pipeline and the data object to a proper state. DisconnectPipeline() calls ProcessObject::SetOutput() to remove the data object from the list of outputs. This triggers a call a DataObject::SetSource() to clear the source field of the data object being disconnected. So the **intent** is that from the user code, only a call to DisconnectPipeline() is needed, with the source field of the data object being reset automatically.

There are a few conditionals in this call stack, so you could be hitting on one of these.

Or, it could be something related to the lifecycle of the smart pointers to “image”.

I would put a breakpoint at the image-\>DisconnectPipeline() call and walk the calls to see why

> <https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Core/Common/src/itkProcessObject.cxx#L472>

  
is not being called.

---

<div class="post-metadata">

**Author:** ![kaspermarstal](https://discourse.itk.org/user_avatar/discourse.itk.org/kaspermarstal/32/211_2.png) [@kaspermarstal](https://discourse.itk.org/u/kaspermarstal)\
**Post date:** [February 5, 2018, 12:10pm UTC](https://discourse.itk.org/t/how-to-really-disconnect-pipeline/551/9 "2018-02-05T12:10:27Z")

</div>

Thank you for your detailed reply Jim. I will do this.
