1

I'm writing a program that loads Dicomfile and makes adjustments.

dll is using clear canvas. However, loading that object into clear canvas seems to cause a strangely significant memory leak. ex) A resource of about 350mb of memory was loaded, but it actually occupies about 1.7G of memory.

This is where the problem arises. clearcanvas was built as a 32-bit program, so I was using 32-bit. That's why GC() is being called. every time because of the 2gb memory limit. OOM problems occur.

RedTriangle is GC

enter image description here

371.231782MB

enter image description here

This is a list stored in my memory. How can I solve this problem?

this is LoadDIcomFile()

 public Bitmap Bitmap;
        public string FilePath;
        public ImageSop ImageSop;
        public DicomFile DicomFile;
        public IPresentationImage PresentationImage;
        public int InstanceNumber = 0;

        public DicomElement(string filePath)
        {
            this.FilePath = filePath;

            DicomFile = new DicomFile(filePath);
            DicomFile.Load();

            ImageSop = new ClearCanvas.ImageViewer.StudyManagement.ImageSop(filePath);

            PresentationImage =
                 PresentationImageFactory.Create(ImageSop.Frames[1]);

            int width = ImageSop.Frames[1].Columns;
            int height = ImageSop.Frames[1].Rows;

            this.Bitmap = PresentationImage.DrawToBitmap(width, height);
            if (DicomFile.DataSet[DicomTags.InstanceNumber] == null)
            {
                throw new Exception("Tag 'Instance Number' not found!");
            }
            this.InstanceNumber = DicomFile.DataSet[DicomTags.InstanceNumber].GetInt32(0, 1);


        }



this is DicomFile.Load(); https://github.com/ClearCanvas/ClearCanvas/blob/master/Dicom/DicomFile.cs

I've been looking for a solution for 5 days, but I can't seem to find it, so I'm asking the question after much deliberation.

로다현
  • 125
  • 1
  • 12
  • 2
    Some suggestions. 1) Dispose of any object that implements the `IDisposable` interface when its no longer needed. 2) Since your 32bit app needs that size of memory, then you need to optimize your declarations. Whenever possible, use `uint` instead of `int`, `byte` instead of `int`...etc. 3) If the mentioned still not enough, then try your app with [LARGEADDRESSAWARE](https://learn.microsoft.com/en-us/cpp/build/reference/largeaddressaware-handle-large-addresses?view=msvc-170) enabled which gives you an additional gigabyte of memory. You need a post-build task to enable that. – dr.null Dec 24 '21 at 07:55
  • 1
    `LARGEADDRESSAWARE` [examples](https://stackoverflow.com/questions/2597790/can-i-set-largeaddressaware-from-within-visual-studio). – dr.null Dec 24 '21 at 08:00
  • 1
    @dr.null it is work thankyou OOM is not visible I'd like to adopt your comment as an answer, but I'm not sure how. – 로다현 Dec 24 '21 at 08:55
  • 1
    Very well. Please post that as answer and accept it. Just summarize your solution. – dr.null Dec 24 '21 at 09:57
  • 4
    `DicomFile` `ImageSop` `PresentationImage` and `Bitmap` are all `IDisposable` and they *must* be disposed, preferably with `using` blocks (and then you would not cache them in fields). Or if you have to cache them then ensure they get disposed if replaced by a new value, and ensure the containing object *also* implements `IDisposable` – Charlieface Dec 24 '21 at 11:54

0 Answers0