How to clear pipeline from memory

Hi,

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?

Thanks.

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
        sliceViewTL.loadImage(ItkToVtkFilter(dicom.GetOutput()).GetOutput())
        sliceViewTR.loadImage(ItkToVtkFilter(label.GetOutput()).GetOutput())
        sliceViewBL.loadImage(ItkToVtkFilter(overlay.GetOutput()).GetOutput())
        ...

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,
Matt

ok I will try that thanks