Strange Memory leak related with volumeNode and segmentationNode

StephenLeePeng
Wed, 27 Sep 2023 15:49:44 +0000
Development

Environment: Slicer 4.13, Linux Ubuntu 20.04.

Background:
Recently, I worked with a project, need to load some nii.gz file, vtp file.
nii.gz file is loaded as vtkMRMLScalarVolumeNode, as the vtp file is loaded by Model, then transform to vtkSegmentationNode.

nii.gz file was generated from a series dcm files by simpleITK, which shape is: 512x512x700, about 350MB.
vtp files was segmented from volume, every vtp file is small part of volume.

Firstly, Iily, I load vtp file as segmentationNode, every vtp file cause memory usage increased 15MB ~ 45MB, the memory is decided by the long and short diameter of segment.
Then I will load another nii.gz file, which is the same patient dcm series, to compare two dcm series change, to help doctor exam the patient.
Also, I will load some vtp files segmented from latter nii.gz file.
The layout will changed at the same time, from classic FourUp layout to customed two group layout, every group has a 3d view and a slice view.

I will switch between two layout frequently. From FourUp layout to customed layout, or customed layout to FourUp layout.
So, I need frequently RemoveNode or clear Scene, then Load nii.gz and vtp file again.

To my confuse, when I Remove the volumeNode, and related displayNode and storageNode, Remove segmentationNode, and clear Scene. And I set the variables to None or empty dict, but the memory usage will not decrease, or decrease only a little, less than loaded memory usage.

Because the memory usage can not decreased to one patient series consumption, So If I reload another series again, the memory will continue to grow up. Finally, the all memory usage will up to
4 ~ 5GB.

And I have read some related topics, and have checked the codes.
There have no Factory method, such as CreateDefaultStorageNode.

Some Clue:
I look the Node Information, and see the volumeNode has 1 reference Count, but the vtkImageData has about 14 reference count.
So I want to know, how I can watch the refercece count from, or is this reason caused the memory leak when I RemoveNode?
How can clean the memry fully or most percent when I RemoveNode and Clear Scene.
@lassoan @pieper

One more question.
The base memory consuption of Slicer app is 700MB above. How can I decrease this basic memory consuption to decrease the highest memory usage of my app.

Any advice will be appreciated.

2 posts - 2 participants