ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 TImageEnMView and Memory
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Flashcqxg

93 Posts

Posted - Jan 13 2021 :  03:08:48  Show Profile  Reply
My code is as follows:
for I := 0 to ImageEnMView.ImageCount - 1 do
  begin
    try
      ImageEnMView.GetBitmap(I);
    finally
      ImageEnMView.ReleaseBitmap(I, False);
    end;
  end;

There are 120 pictures in ImageEnMView, each picture is about 80kb.When this program is executed for the first time, the program occupies about 30M of memory. After the second time, each execution occupies a maximum of about 1.2G of memory. Is this normal?
Thanks.

xequte

38182 Posts

Posted - Jan 13 2021 :  19:15:38  Show Profile  Reply
Hi

GetBitmap converts the internal storage of images to TBitmap, which has poor memory handling.

You are better to use TImageEnMView1.GetTIEBitmap. If you need a TBitmap use TIEBitmap.CopyToTBitmap to copy the result to your bitmap.

const
  USE_GETBITMAP = False;
var
  I: Integer;
  bmp: TBitmap;
  iebmp: TIEBitmap;
begin
  for I := 0 to ImageEnMView1.ImageCount - 1 do
  begin
    bmp := nil;
    try
      Caption := IntToStr( i ) + ' - ' + ImageEnMView1.ImageFilename[i];

      if USE_GETBITMAP then
        bmp := ImageEnMView1.GetBitmap(I)
      else
      begin
        bmp := TBitmap.Create;
        iebmp := ImageEnMView1.GetTIEBitmap(I);
        iebmp.CopyToTBitmap( bmp );
      end;

      // do somethign with bmp...
    finally
      if not USE_GETBITMAP then
        FreeAndNil( bmp );
      ImageEnMView1.ReleaseBitmap(I, False);
    end;
  end;
  MessageBeep(0);
end;


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

Flashcqxg

93 Posts

Posted - Jan 14 2021 :  03:30:24  Show Profile  Reply
Hello xequte,i have test the code,but same.
After the second time, each execution occupies a maximum of about 1.2G of memory.
Go to Top of Page

xequte

38182 Posts

Posted - Jan 14 2021 :  20:57:44  Show Profile  Reply
Hi

The process above will load all images (if they were not previously loaded) into the TImageEnMView. Storage will be based on StoreType:

https://www.imageen.com/help/TImageEnMView.StoreType.html

So if StoreType is ietNormal, for instance, and images were loaded on demand (so not all initially loaded) then your code above will force the loading of all the images into memory. After the process completes they would remain in memory.

That doesn't explain why it wouldn't happen the first time though, so I suspect something else is going on. Can you email me a small demo project that shows the issue.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

Flashcqxg

93 Posts

Posted - Jan 14 2021 :  21:30:30  Show Profile  Reply
Hi
I have emailed the demo.
Go to Top of Page

xequte

38182 Posts

Posted - Jan 14 2021 :  21:56:40  Show Profile  Reply
Thanks, I can reproduce the issue and we are investigating.



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

xequte

38182 Posts

Posted - Jan 18 2021 :  16:50:27  Show Profile  Reply
Thanks,

This behavior is due to the way images are cached, which after subsequent runs reaches a maximum of 100 cached images (by default), i.e. 1GB (each image is 1654x2339 = 11MB x 100 = 1100MB).

To reduce the memory footprint, you can set ImageEnmView1.ImageCacheSize to a smaller number like 10.

https://www.imageen.com/help/TImageEnMView.ImageCacheSize.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

Flashcqxg

93 Posts

Posted - Jan 18 2021 :  18:47:34  Show Profile  Reply
Thank you, now it works!
Go to Top of Page

zhengyuanyi27

58 Posts

Posted - May 29 2021 :  22:49:26  Show Profile  Reply
Just to report a weard problem about "out of memory" and its solution method.
The following code (if saveimaggendialog1.Execute then Imageenmview1.IO.LoadFromFileDICOM(...);) will cause "out of memory" error when loading some DICOM file (It always works well before loading the DICOM file from the latest ultrasound machine of Philips company.)

The solution is very easy but it took me a lot of time to find it.
The solution is: Replace saveimaggendialog1.Execute with savedialog1.Execute, then it works well as before.
Go to Top of Page

xequte

38182 Posts

Posted - May 31 2021 :  03:40:17  Show Profile  Reply
Hi

Can you please email me a DICOM file that reproduces this issue.


Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: