It can be a bit of a bear of a task, but generally there seem to be some pretty common method usages that cause the memory leaks.
I would guess it is because you are using some methods like
GetNodesByClass rather than something like
for i in range(slicer.mrmlScene.GetNumberOfNodesByClass('vtkMRMLSegmentationNode')):
segmentation_node = slicer.mrmlScene.GetNthNodeByClass(i, 'vtkMRMLSegmentationNode')
Also things like
CreateNodeByClass can cause memory leaks, but can be avoided by using
See Documentation/Nightly/Developers/Tutorials/MemoryManagement - Slicer Wiki for more details.
Also related is Memory leaks when returning vtkCollection objects to Python as return value · Issue #2718 · Slicer/Slicer · GitHub.