Sunday 15 May 2011

c# - Windows Phone Images Grid "Out of memory" error -



c# - Windows Phone Images Grid "Out of memory" error -

i have "out of memory" exception on windows phone when seek display grid of images. played code little , think grid.children.add gives me error.

i've made custom class shows grayness rectangle , after image loaded, shows image instead of rectangle. here is:

class imagewithloader { private bitmapimage m_loader_bitmap; private bitmapimage m_source_bitmap; private image m_image; public image image { { homecoming m_image; } } //url - url 120x120 image; width, height = 120 both public imagewithloader(string url, int width, int height) { m_image = new image(); m_loader_bitmap = new bitmapimage(new uri("assets/images/image_await_background.png", uri kind.relative)); m_loader_bitmap.decodepixelwidth = width; m_loader_bitmap.decodepixelheight = height; m_image.source = m_loader_bitmap; m_source_bitmap = new bitmapimage(new uri(url)); m_source_bitmap.createoptions = bitmapcreateoptions.none; m_source_bitmap.imageopened += bitmaploaded; } private void bitmaploaded(object sender, routedeventargs e) { m_image.source = m_source_bitmap; m_loader_bitmap.urisource = null; } }

and in class add together these images grid (it's series of them, loaded url parsed json)

private void addimagetogrid(imagewithloader loader_image, int row, int col) { double margin = 0.05 * pic_width; loader_image.image.setvalue(grid.columnproperty, col); loader_image.image.setvalue(grid.rowproperty, row); loader_image.image.margin = new thickness(margin); //comment out string , everythins goes fine images_grid.children.add(loader_image.image); }

to guess comments: i've made saving imagewithloader-s list<> prevent gc collect them. imagewithloader url url of 120x120 images, must not heavy.

part of xaml page images grid:

.... <scrollviewer x:name="scrollview" horizontalalignment="left" height="603" verticalalignment="top" width="456" > <grid x:name="images_grid" height="596" width="453"/> </scrollviewer> ....

so, please, doing wrong? should utilize command instead of grid? or there else missing?

p.s. sorry misinform. size 120x120 displayed rectangle, images loaded have sizes 800x800 (for example) , after fit 120x120 rectangle.

p.p.s. if remove loading m_loader_bitmap, pictures displayed fine. m_loader_bitmap 1px grayness png

hi alter code this

public void imagewithloader(string url, int width, int height) { deployment.current.dispatcher.begininvoke(() => { m_image = new image(); m_loader_bitmap = new bitmapimage(new uri("assets/images/image_await_background.png", urikind.relative)); m_loader_bitmap.decodepixelwidth = width; m_loader_bitmap.decodepixelheight = height; m_image.source = m_loader_bitmap; m_loader_bitmap = null; m_source_bitmap = new bitmapimage(new uri(url)); m_source_bitmap.createoptions = bitmapcreateoptions.none; m_source_bitmap.imageopened += bitmaploaded; }); }

or find more these link

memory leak bitmapimage

memory consumption of bitmapimage/image command in windows phone 8

writeablebitmap memory leak

system.outofmemoryexception

c# xaml windows-phone-8 out-of-memory

No comments:

Post a Comment