Compare Image Out of Memory error

Ask general questions here.
mtkilic
Posts: 9
Joined: Tue Jan 15, 2019 4:12 pm

Compare Image Out of Memory error

Post by mtkilic » Thu Apr 04, 2019 4:38 pm

I am seeing below error, however I don't get same error when running in different machine.

Code: Select all

[2019/04/03 15:33:17.579][Info   ][Exception]: Exception occurredSystem.OutOfMemoryException: Out of memory.
   at System.Drawing.Bitmap..ctor(String filename)
   at CDIS_V11.FunctionalLibrary.CL.ImageValidation(Element item, String test1, String test2, Double options) in d:\ranorex\utilities\qa\ranorex\V22\CDIS_V21\Functional Library\CL.cs:line 256
Here is the Line 256 code

Code: Select all

bool isCreated= Validate.CompareImage(item,new Bitmap(test1),MyFindOptions,"test",options1);
Image Properties:
dimensions: 25600x1489
size: no more than 500k
type: PNG

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Compare Image Out of Memory error

Post by odklizec » Thu Apr 04, 2019 5:30 pm

Hi,

My guess is, that the computer where you getting this error is equipped with less RAM, than the other one?

File size 500kB does not represent exact memory footprint of an image, especially if the image is compressed (like PNG or JPG). You can calculate exact memory required for an image, like this...
image width * image height * 4
So your png image requires about 150MB of RAM. Because you are comparing two images, there must be at very least 300MB of free RAM and I guess the comparison procedure requires even a bit more for buffering and comparison itself? So the file size is really not so important here. The image resolution is ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

mtkilic
Posts: 9
Joined: Tue Jan 15, 2019 4:12 pm

Re: Compare Image Out of Memory error

Post by mtkilic » Thu Apr 04, 2019 5:48 pm

After re-running test on same computer this time I didn't get Out of Memory error.
All the computer has same ram (64) and 64-bit

This is really confusing why I get this sometimes. I have set of test suites and when I fully run this test suites, one of the test cases have this error. Like I said its not always same image comparison or same machine.

mtkilic
Posts: 9
Joined: Tue Jan 15, 2019 4:12 pm

Re: Compare Image Out of Memory error

Post by mtkilic » Thu Apr 11, 2019 4:55 pm

I am still having this issue. can I get some help please.

ahoisl
Certified Professional
Certified Professional
Posts: 192
Joined: Fri Sep 07, 2007 8:16 am

Re: Compare Image Out of Memory error

Post by ahoisl » Thu Apr 11, 2019 7:10 pm

mtkilic wrote:
Thu Apr 04, 2019 4:38 pm
Image Properties:
dimensions: 25600x1489
size: no more than 500k
type: PNG
You have to realize that in memory this is a really large image - the file size does not matter at all, since PNG compresses the data on disk.
In memory, the image will take up at least 25600x1489x4B = 153MB, and this is without any overhead of loading the image, data structures, or .NET memory management. And if you load a second image of similar size to compare to, you will require more than 310 MB just for those two images - double that if you also load the memory from a file and don't dispose of all the intermediate data structures right away.

One thing I noticed is that you use the "new Bitmap" constructor to load an image. .NET has a built in defect with bitmap handling as it does not always account for all the unmanaged (native) memory a bitmap uses.
Instead of using this constructor, rather use the Ranorex Imaging.Load method which guards against that problem and instructs .NET to clean up unused image data if too much native memory is piled up. If you don't use the Ranorex method, make sure to Dispose all images after use, otherwise they may keep in memory for a longer time and cause OutOfMem exceptions.

Regards,
Alex
Ranorex Team

mtkilic
Posts: 9
Joined: Tue Jan 15, 2019 4:12 pm

Re: Compare Image Out of Memory error

Post by mtkilic » Thu Apr 11, 2019 9:45 pm

I did use Imaging.Load but this time failed error is

Code: Select all

Exception]: Exception occurredSystem.ArgumentException: Failed to load bitmap from file 'D:\..\xx.png'. ---> System.OutOfMemoryException: Out of memory.
   at System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement)
   at Ranorex.Imaging.Load(String filename)
   --- End of inner exception stack trace ---
   at Ranorex.Imaging.Load(String filename)
   at CDIS_V11.FunctionalLibrary.CL.ImageValidation(Element item, String test1, String test2, Double options) in d:\ranorex\utilities\qa\ranorex\V22\CDIS_V21\Functional Library\CL.cs:line 256
I double checked, if I copy and paste file path, image is openning, so image is there. But before this fail in my ranorex report it also shows "Searched image" (null). I am using compare image function in 100s of tests, only couple throw this error.

ahoisl
Certified Professional
Certified Professional
Posts: 192
Joined: Fri Sep 07, 2007 8:16 am

Re: Compare Image Out of Memory error

Post by ahoisl » Fri Apr 12, 2019 8:05 am

For analysis, you could log the system information before doing image comparisons using following code. Then you would see the memory allocation in your current process/system:
Report.SystemSummary();
If that does not help, we will probably need to look at your solution or the images and for that you need to get in touch with our support directly, please:
https://www.ranorex.com/support-query/

Regards,
Alex
Ranorex Team