Hi,
I have a windows (VS2005) C# form that contains ultrapicturebox controls on it. I create them on the fly as I need them, depending on the number of Images I need to display to the user.
Problem: After opening and closing the form a number of times (maybe 30) (without closing the program), I am getting a OUT OF MEMORY error, and I know it is because the images are not getting released properly. Even though I am 'Disposing' and 'Garbage Collecting', these images are still not being released from memory.
Does anyone have a solution to this problem?
I am using v5.3 of Infragistics controls.
Does a newer version resolve this issue?
Thanks,
Dan
Hi Dan,
dancarlile said:I know it is because the images are not getting released properly
How do you know this?
Are you clearing the UltraPictureBox control's reference to the image? Are you displosing of the controls?
It's really impossible to guess what's causing a memory leak without seeing exactly what you code is doing and maybe running it through a memory profiler. Can you duplicate this behavior in a small sample project and Submit an incident to Infragistics Developer Support?
Here is some code.
private
e)
{
//foreach (PictureBox pb in pnlPicBox.Controls)
(pnlPicBox.Controls.Count > 0)
pnlPicBox.Controls)
ctrl.Dispose();
}
(pnlInvoiceImages.Controls.Count > 0)
pnlInvoiceImages.Controls)
.Forced);
.WaitForPendingFinalizers();
Thanks for explaining this. I was thinking that since I was disposing of the Picbox control, that the Image property would be cleared also. I have added this code to dispose of the Images. I have received no memory errors since.
foreach
(Infragistics.Win.UltraWinEditors.UltraPictureBox pb in pnlPicBox.Controls)
Image i = (Image)pb.Image;
if (i != null)
{i.Dispose();}
Thanks again.
Well, it's a bit hard to read this code, but unless I am missing it, I don't see anything here that would dispose the images. You are just disposing the UltraPictureBox controls. But the control can't assume that the image you provided is not being used by anything else, so it can't dispose the images.
You, the developer, are responsible for disposing any images you create in your code. Assuming you are assigning the images at run-time in code.If you are applying the images at design-time through the properties of the UltraPictureBox, then that would certainly be a serious problem.
How are you loading the images? You say you cannot load them into another program, so I assume your images are coming from image files on the hard drive. But I can't see any reason why loading an image from a file should lock the file from being used by other applications.
The reason I know the pictureboxes are not releasing the images is because I cannot load them using another program until I close the current Program.