Groups | Blog | Home
all groups > dotnet compact framework > april 2007 >

dotnet compact framework : Out of Memory Exception



Murthy
4/29/2007 3:18:01 AM
Hi,
I want to display the Photos from a Folder in a Picture Box for my windows
mobile 5.0 application.
User can view the photos by pressing the Next Button.

But it is throwing out of memory Exception when he navigates through more
than 5 photos.

Here is my code.

private void ShowPhoto()
{
PicBxPhoto.Image = null;
Bitmap BmpPhoto = null;
// sets the path for the Bitmap
BmpPhoto = new Bitmap(PhotoList[iSelPhotoIndex].FullName);
// Display the selected photo in the picture box
PicBxPhoto.Image = BmpPhoto;
// free the bitmap after display
BmpPhoto.Dispose();
BmpPhoto = null;
}
}

private void BtnNext_Click(object sender, EventArgs e)
{

if (PhotoList.Length != iSelPhotoIndex + 1)
{
// Load the next photo in the Photolist
iSelPhotoIndex++;
string[] photoName =
PhotoList[iSelPhotoIndex].Name.Split('.');
// display the corresponding Job No. and Creation time of
the photo
LblName.Text = photoName[0];
LblDateTime.Text =
PhotoList[iSelPhotoIndex].CreationTime.ToString();
// display the photo in picture box
ShowPhoto();
LblName.Refresh();
LblDateTime.Refresh();
}
}

Can someone please tell me why this small code is throwing Out of Memory
Exception?

Thanks,
Murthy

Richard Jones
4/29/2007 3:49:16 AM
Just for an expirement (I've just had a really quick look) try it
without

// free the bitmap after display
BmpPhoto.Dispose();
BmpPhoto = null;



[quoted text, click to view]

Murthy
4/29/2007 5:08:02 AM
I tried with out
// free the bitmap after display
BmpPhoto.Dispose();
BmpPhoto = null;

I added this code trying to avoid the Exception, but it did not work.

The only variable i am using on clicking Next is the Bitmap BmpPhoto variable.
I am assigning the new photo image to this variable.
And this is throwing the OOM Exception on clicking some 4 or 5 times.

Can someone tell me what is the problem.

Thanks,
Murthy

[quoted text, click to view]
Murthy
4/29/2007 10:34:00 AM
I am already making the BmpPhoto Null.
I am only using the BmpPhoto object....

Is that the reason.

Does .NET CF 2.0 have any issues?

Thanks,
Murthy

[quoted text, click to view]
Adam
4/29/2007 2:58:04 PM
Dnia Sun, 29 Apr 2007 03:18:01 -0700, Murthy napisa³(a):

[quoted text, click to view]
[cut]

Try this.


Bitmap BmpPhoto = null; //1

private void ShowPhoto()
{
PicBxPhoto.Image = null;
//Bitmap BmpPhoto = null; //1
// sets the path for the Bitmap
BmpPhoto = new Bitmap(PhotoList[iSelPhotoIndex].FullName);
// Display the selected photo in the picture box
PicBxPhoto.Image = BmpPhoto;
// free the bitmap after display
BmpPhoto.Dispose();
BmpPhoto = null;
}
}

private void BtnNext_Click(object sender, EventArgs e)
{

if (PhotoList.Length != iSelPhotoIndex + 1)
{
// Load the next photo in the Photolist
iSelPhotoIndex++;
string[] photoName =
PhotoList[iSelPhotoIndex].Name.Split('.');
// display the corresponding Job No. and Creation time of
//the photo
LblName.Text = photoName[0];
LblDateTime.Text =
PhotoList[iSelPhotoIndex].CreationTime.ToString();
// display the photo in picture box
ShowPhoto();
LblName.Refresh();
LblDateTime.Refresh();
}
Peter Morris
4/29/2007 7:11:08 PM
[quoted text, click to view]

//Try adding this.....
if (PicBxPhoto.Image != null)
PicBxPhoto.Image.Dispose();

[quoted text, click to view]


AddThis Social Bookmark Button