Memory problem with images

  • Thread starter Thread starter alberto.decaro
  • Start date Start date
A

alberto.decaro

Hello everybody,
I'm developing a ppc application that receives images from a url and
periodically displays them in a picturebox (I use a timer control).

private sub tick(...) handles myTimer.tick
'pbx is the target picturebox control
pbx.image = getImage()
end sub

private function getImage() as bitmap
'strUrl is the stream containing the image
return new bitmap(strUrl)
end function

The problem is that at each ticking a new bitmap object is created
exhausting memory resources.
I'd like creating a bitmap object once and using a '.FromStream' method
at each ticking, but the Image.FromStream static method is not
evailable for the compact framework.

Any clue?
 
Try to explicitly dispose image before assigning the new one to a
picture box:

private sub tick(...) handles myTimer.tick
'pbx is the target picturebox control
if pbx.image is nothing then pbx.image.Dispose()
pbx.image = getImage()
end sub

About your second question:- the Bitmap class has Stream parameter in
one of its constructors:

Bitmap b = new Bitmap(Stream);
 
Back
Top