1

I am getting out of memory exception randomly , I am downloading heavy images in my project from AWS. how to solve the issue

[369][4/29/2011 18:32:15:343]-ERR -[ThreadId = 7916, UIFramework_ICEVisionPro_GUIExceptionHandler.LogException]-System.OutOfMemoryException: Out of memory.

   at System.Drawing.Graphics.FromHdcInternal(IntPtr hdc)

   at System.Drawing.BufferedGraphicsContext.CreateBuffer(IntPtr src, Int32 offsetX, Int32 offsetY, Int32 width, Int32 height)

   at System.Drawing.BufferedGraphicsContext.AllocBuffer(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)

   at System.Drawing.BufferedGraphicsContext.AllocBufferInTempManager(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)

   at System.Drawing.BufferedGraphicsContext.Allocate(IntPtr targetDC, Rectangle targetRectangle)

   at System.Windows.Forms.Control.WmPaint(Message& m)

   at System.Windows.Forms.Control.WndProc(Message& m)

   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)

   at System.Windows.Forms.ContainerControl.WndProc(Message& m)

   at System.Windows.Forms.UserControl.WndProc(Message& m)

   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
piet.t
  • 11,718
  • 21
  • 43
  • 52
Sagar Bhatnagar
  • 486
  • 2
  • 11

1 Answers1

-2

compress the downloaded bitmap as below

FileOutputStream fos = new FileOutputStream(output.getPath()); myBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);

Here 100 meaning compress for max quality.

kumud kala
  • 117
  • 6
  • That's not going to help. That writes it to disk. It does not compress the amount of memory used to store it in RAM for drawing. – Gabe Sechan Sep 11 '18 at 06:21