Paul Martinez
Paul Martinez

Reputation: 562

System.OutOfMemory BitmapImage WP8

I got a OutOfmemory error when i create a list of bitmapimage...

What am i supposed to do...?

Thanks for your help ;)

Here is my code :

     foreach (var bytearray in imageDataBlocksPresta)
            {
                if (bytearray != null)
                {
                    MemoryStream ms;
                    using (ms = new MemoryStream(bytearray, 0, bytearray.Length))
                    {
                        BitmapImage photo = new BitmapImage();
                        photo.DecodePixelHeight = 800;
                        photo.DecodePixelWidth = 624;
                        photo.SetSource(ms);//ERROR

                        listphotoPresta.Add(photo);
                    }
                }

                else//si photo null
                {
                    BitmapImage photo = new BitmapImage();
                    photo.DecodePixelHeight = 800;
                    photo.DecodePixelWidth = 624;
                    photo.UriSource = new Uri("/Images/NoImageIcon.jpg", UriKind.RelativeOrAbsolute);

                    listphotoPresta.Add(photo);

                }

Upvotes: 0

Views: 416

Answers (2)

Bailey Stein
Bailey Stein

Reputation: 331

Try setting photo to null and calling GC.Collect() once you've added it. Like this:

listphotoPresta.Add(photo);

photo = null;
GC.Collect();

Upvotes: 2

Andras Csehi
Andras Csehi

Reputation: 4305

  • Don't create NoImageIcon all the time. Use only one reference
  • Don't try to store all images in memory. It's a mobile.
  • Limit your app for devices with at least 512MB RAM
  • Store lower resuolution pictures. 800*600 is full screen on many devices
  • Load images on demand
  • Call GC right after you release an image

Upvotes: 0

Related Questions