Bitmap Objects throws Out Of Memory Exception

  • Thread starter Thread starter globus2410
  • Start date Start date
G

globus2410

Hi ,

I've a NET CF apply that shows a thumbnails list. Thumbs are shown as
four for page and users can navigate forward and backward through
pages.

To show thumbs I simply used

PictureBox.Image = new Bitmap(path);

Before filling Image property I check them and , if needed , I dispose
their bitmaps .

if(PictureBox.Image!=null)
PictureBox.Image.Dispose();

The problem :
When navigating through my thumbs my app randomly throws an "Out Of
Memory Exception" ....

I also tried to load Bitmaps using filestream , but nothing changed.

It seems that Bitmap Objects are not really disposed .... is it
possible? How can I solve that? How do you handle multiple bitmaps on
CF applications? Where i'm wrong?

Thank you ,
Nicola
 
Hi,

I had the same problem, try to remove your pictureBox from its parent
control.
try
{
this.Controls.Remove(PictureBox);
}
catch (ObjectDisposedException)
{
}
if(PictureBox.Image!=null)
PictureBox.Image.Dispose();

or try to Dispose your PictureBox.

It works fine for me.

BR


Fabien Decret
Windows Embedded Consultant

ADENEO (ADESET)
http://www.adeneo.adetelgroup.com/




(e-mail address removed) a écrit :
 
Hey Globus2,

Take a look at this blog by ctacke... Once you have a good grip on the
material here, the whole bitmap OutOfMemory Exception problem should be
cleared up. Here is also another blog from MS's Scott Holden covering
the same subject matter
http://blogs.msdn.com/scottholden/archive/2006/08/22/713056.aspx.

The only additional point I'd add is to make sure your bitmaps are
compressed using a standard jpeg compression algorithm. Certain jpeg
encodings will not render on handhelds, rather, they will cause a OOM
exception.
 
Hi,

------------------------------------
http://blog.opennetcf.org/ctacke/PermaLink,guid,987041fc-2e13-4bab-930a-f79021225b74.aspx
says that:

while (true)
{
Bitmap b = new Bitmap (stream);
}

will run forever.

------------------------------------
However,

http://blogs.msdn.com/scottholden/archive/2006/08/22/713056.aspx says that:

while (true)
{
Bitmap b = new Bitmap (stream);
}

will caused the allocation to fail.

So which is it? Who's blog is correct?

Hilton "Still wishing Bitmap constructors worked the same with regards to GC
and performance and that down the line, we could be confident that future CF
versions would change everything on us."
 
As I wrote in first post I also used a stream as bitmap builder but
apply still throws out OOM exceptions.
Note that this problem only occours on the real device (Mobile 5) , not
in emulator and nor as a normal NET apply on a desktop PC ....

That's the code :

fs = new System.IO.FileStream(path System.IO.FileMode.Open);
pictureBox.Image = new Bitmap(fs);
fs.Close();
fs = null;

when user change page I call :

pictureBox.Image.Dispose();
pictureBox.Image = null;

And then again the "image builder".

I'm going to try Fabien's suggestion (thank you) , but I cannot really
think that's the best way to do that....

Nicola
 
Back
Top