Out of Memory Exception

G

Guest

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
 
R

Richard Jones

Just for an expirement (I've just had a really quick look) try it
without

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

Guest

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

Richard Jones said:
Just for an expirement (I've just had a really quick look) try it
without

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



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
 
A

Adam

Dnia Sun, 29 Apr 2007 03:18:01 -0700, Murthy napisa³(a):
Hi,
I want to display the Photos from a Folder in a Picture Box for my windows
[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();
}
}
 
G

Guest

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

Adam said:
Dnia Sun, 29 Apr 2007 03:18:01 -0700, Murthy napisał(a):
Hi,
I want to display the Photos from a Folder in a Picture Box for my windows
[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();
}
}
 
P

Peter Morris

private void ShowPhoto()

//Try adding this.....
if (PicBxPhoto.Image != null)
PicBxPhoto.Image.Dispose();
PicBxPhoto.Image = null;
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;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top