Object/Memory Management of DicomImage and DicomDataSet
The following diagram shows the relationship between DicomImage and DicomDataSet objects.
DicomImage object
DicomImage contains DicomDataSet which holds the pixel data.
DicomImage.Dispose() method does not need to be called explicitly as it will get cleaned up eventually via a finaliser when called from the Garbage Collector.
The following objects are cleared when DicomImage object is disposed:
- All DicomLabels attached to the DicomImage object
- All Caches, including Unmanaged (DirectX for example) objects
- If the Image is a DICOM encapsulated PDF and displayed in the built-in PDF viewer, that PDF viewer control also gets disposed.
DicomDataSet object
DicomDataSet object contains all DICOM attributes, including pixel data. It also contains the Textures when in DirectX mode.
DicomDataSet.Dispose() method does not need to be called explicitly as it will get cleaned up eventually via a finaliser when called from the Garbage Collector.
The following objects are cleared when DicomDataSet object is disposed:
- Pixel Data
- All other DICOM attributes
- Textures
Note
Disposing DicomImage object does not necessarily dispose the DicomDataSet object the image contains, as the above diagram shows it is possible to construct 2 DicomImage objects that share the same DicomDataSet object. To clean things up more predictably, it is best to call Dispose on both the DicomImage and the DicomDataset (assuming that no other images are using the dataset) in either order.
Unmanaged Resources
There are a few unmanaged resources being used:
- DirectX textures etc - cleaned up when the Pixel Data object is disposed (when the containing DicomDataSet object is disposed)
- ActiveX control used to display PDF in DicomVIewer object - cleaned up when the DicomImage object is disposed
- FFMPEG for MPEG import/export etc. - cleaned up when the Pixel Data object is disposed (when the containing DicomDataSet object is disposed)