System.OutOfMemoryException

Ask general questions here.
User avatar
slavikf
Posts: 104
Joined: Mon Sep 13, 2010 9:07 pm
Location: Toronto, Canada
Contact:

System.OutOfMemoryException

Post by slavikf » Fri Feb 04, 2011 12:45 am

During executing following code:
Bitmap image = Imaging.Load (RestoreDB.SSDir+"TC207.png");
Validate.ContainsImage (repo.FormOIS_WinStation_11_EyeSca.Element59648Info, 
	image.Clone ( new Rectangle (3,3,imageOrig.Width-6,imageOrig.Height-6),image.PixelFormat),
	Imaging.FindOptions.Default, 
	"TC207: Validation of 'Sharpened proofsheet' image", 
	false);
i got following error:
Unexpected exception occured: System.OutOfMemoryException: Out of memory.
at System.Drawing.Bitmap.Clone(Rectangle rect, PixelFormat format)
at Review1.Recording1.TC207() in c:\AutoRex\Review1\Review1\Recording1.UserCode.cs:line 1514
at Review1.Recording1.Start() in c:\AutoRex\Review1\Review1\Recording1.cs:line 159
at Review1.Program.Main(String[] args) in c:\AutoRex\Review1\Review1\Program.cs:line 36


Any idea where to go to troubleshoot?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: System.OutOfMemoryException

Post by Support Team » Fri Feb 04, 2011 9:37 am

From the stack trace it looks like this exception is coming from the image.Clone method you use that's part of the .NET Framework API. Unless you did really run out of memory, from what I remember that exception is also thrown by that method if the provided PixelFormat is wrong or not supported or the rectangle is not correct – really intuitive, isn't it?

Please, try to use the equivalent Ranorex method Imaging.Crop instead.

Regards,
Alex
Ranorex Team
.
Image

User avatar
slavikf
Posts: 104
Joined: Mon Sep 13, 2010 9:07 pm
Location: Toronto, Canada
Contact:

Re: System.OutOfMemoryException

Post by slavikf » Fri Feb 04, 2011 9:26 pm

Support Team wrote:From the stack trace it looks like this exception is coming from the image.Clone method you use that's part of the .NET Framework API. Unless you did really run out of memory, from what I remember that exception is also thrown by that method if the provided PixelFormat is wrong or not supported or the rectangle is not correct – really intuitive, isn't it?
You are absolutely correct - i was using wrong rectangle size...! How did you know :shock: ?
Problem solved...

Thank you...

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: System.OutOfMemoryException

Post by Support Team » Sat Feb 05, 2011 11:04 am

slavikf wrote:You are absolutely correct - i was using wrong rectangle size...! How did you know :shock: ?
I'm good at guessing :wink: Seriously, I stumbled over the same exception once and couldn't get my head around why an OutOfMemoryException is thrown in that case...

Regards,
Alex
Ranorex Team
.
Image