Hi,
while using the following environment:
.NET Memory Profiler 3.1 with Dispose Tracker activated
Visual Studio 2005
.NET Framework 2.0
and executing the following code snippet:
try
{
Image image = this.imageList1.Images[0];
image.Dispose();
}
catch
{
// Do whatever you want here to record the fact that, for whatever reason, an exception has been thrown
// between the above lines
// Image image = this.imageList1.Images[0];
// and
// image.Dispose();
// This assures that Image.Dispose() is actually called
}
I found out that .NET Memory Profiler detects an undisposed instance of the System.Drawing.Bitmap type. Looking at the allocation stacks of the Delta Undisposed Instances, it ended up to be exactly the above snippet that caused the detection.
But, as you can see, Image.Dipose() gets called for sure, a fact that is enforced by the use of the try-catch block.
So, drilling down further into the stack, I found that the line
Image image = this.imageList1.Images[0];
calls the underlying
Bitmap.FromGDIplus(IntPtr)
Image.FromHbitmap(IntPtr, IntPtr)
Image.FromHbitmap(IntPtr)
ImageList.GetBitmap(int)
ImageList.ImageCollection.get_Item(int)
(stack truncated for brevity)
So, since my code above actually disposes the Bitmap, I actually wonder if other internal routins of .NET allocates and then don't dispose other Bitmaps.
Any help from anyone?
Thank you in advance
System.Drawing.Image.Dispose() issue
-
- Posts: 1030
- Joined: Wed Mar 02, 2005 7:53 pm
I have posted a reply to this post in the "Using .NET Memory Profiler" forum.
Best regards,
Andreas Suurkuusk
SciTech Software AB
Andreas Suurkuusk
SciTech Software AB
Who is online
Users browsing this forum: No registered users and 1 guest