How to clear pipeline from memory


I notice that I have a memory build up then eventually crashes my program after calling load about 3 times. Everything I call load it will create new pipelines and eventually ends in a VTK image viewer. there is only 1 image viewer which I call SetInputData again to load the new data. But how do I make sure that the previous pipeline is deleted before loading the new one?


def load():
        # these are just ITK source -> filter pipes
        dicomSource, dicom   = DicomModel(series[uid])
        labelSource, label        = LabelMapModel(dicom.GetOutput(), ndarr=argMax)
        overlay                         = OverlayModel(series[uid], ndarr=argMax)

        # load models into VTK image viewer

Hi @benjaminhon,

A few things may help.

  1. Call the Python del builtin to delete objects / images.
  2. Call .ReleaseDataFlagOn() on pipeline filters, and they will release the memory they use between pipeline executions.

Hope this helps,

ok I will try that thanks