Problem with Memory Leak I think and PictureBox

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
 
P

pkellner

Where would I do the dispose in my example? I don't think I want to
dispose of the picturebutton.
 
S

Sergey Bogdanov

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;
 

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