| First, related to deleting the underlying bitmap. In the low-level Win32
| code, the bitmap is reused and managed, there. This is code that's been
| around for many years and is stable which is why I don't want to fiddle
with
| it (but I probably will have to in the coming months).
Glad to know that. If the hBitmap will be reused, then we don't need to
delete it after creating the Bitmap object.
| Third, the proposed solution to move the dispose seems a bit fragile.
What
| is needed is a callback or method like is sued for the asynchronous load
for
| a pictureBox. In that way, the control could notify the caller when it's
done
| with the object. What's a bit odd is that it seems as though the
| pictureBox.image call is actually doing things asynchronously, else this
| would not be a problem. Is there a way to know, for sure, that the image
is
| done being displayed so that the data it was copying from can be
discarded?
| It's obvious that the call completing is not an indication that it's save
to
| dispose it.
The only time to Dispose the image is the when it is no longer needed. By
that, I mean at the time there is no reference that will use the image
again.
If the image is still be displayed in the PictureBox, then the PictureBox
holds a reference to it, when the OnPaint event happens, the PictureBox
needs the image to redraw itself.
So I think the best safe time to Dispose the old image is right after the
new image is assigned to the PictureBox.
Image old = this.theImage.Image;
this.theImage.Image = theBitmap;
if (old != null) old.Dispose();
I should have added this in my previous post.
Image.Dispose() for your reference:
http://msdn.microsoft.com/en-us/library/8th8381z.aspx
Note the Remarks section.
Hope this helps.
Best regards,
Jie Wang ((E-Mail Removed), remove 'online.')
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(E-Mail Removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.
Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.