Efferent-Health / fo-dicom.Codecs

Cross-platform Dicom native codecs for fo-dicom
Other
64 stars 22 forks source link

Dispose PinnedByteArrays #55

Closed bcarthic closed 7 months ago

bcarthic commented 8 months ago

Description This PR includes changes that will dispose PinnedByteArray that is holding memory while doing transcoding.

Repo Here is the sample code that will reproduce the memory being not cleaned by the garbage collection. In the sample, I am transcoding a dicom instance from Explicit VR Little Endian transfer syntax to JPEG 2000 Image Compression (Lossless Only) transfer syntax. This is because, PinnedByteArrray are not disposed while doing transcoding when using DicomJpeg2000LosslessCodec or DicomJpeg2000LossyCodec. But the same PinnedByteArray is cleaned properly in JpegNativeCodec implementation.

You can see below, when transcoding a file for 5 times, the memory stays high and not garbage collected.

image image

From the above memory profiler, we can see that the byte[] is not garbage collected and classified by the memory profiler as "dead object".

We believe that the Gen 2 GC not happening, since it is allocated in large object heap.

Solution

image

Testing Ran Unit and Acceptance test.

bcarthic commented 8 months ago

@jaime-olivares , could you please take a look

jaime-olivares commented 8 months ago

We will review in the following days --Jaime.

jaime-olivares commented 8 months ago

We have already scheduled the revision, testing and approval of this PR for next week.