Problem with Memory Leak I think and PictureBox

  • Thread starter Thread starter pkellner
  • Start date Start date
P

pkellner

I'm using CF 1.1 and am using a picturebox control to implement virtual
scrolling. That is, when the person presses the arrows, I replace the
Image in the control. I've got 20 or so images I swap in and out with
code like the following:

Rectangle srcRect = pageLetArray[currentRow,
currentCol].localRectangle;

Image newImage = Crop(fullYPImage, destRect, srcRect);

pb.Image = newImage;

After pressing the up and down about 10 or 15 times, I get an out of
memory error. I'm thinking the gc should take care of this when I do
the pb.Image = newImage but it doesn't seem to be doing it quickly
enough.



thanks,

Peter Kellner

http://peterkellner.net
 
Where would I do the dispose in my example? I don't think I want to
dispose of the picturebutton.
 
We do not see Crop implementation but can suppose that it always create
new Image object. Thus you have to rewrite the code provided by you in
this way:

Image newImage = Crop(fullYPImage, destRect, srcRect);

//---

if (pb.Image != null) pb.Image.Dispose();

//---

pb.Image = newImage;
 
Back
Top