Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - BitmapSource Disposal/cleanup

 
 
Old 07-24-2006   #1 (permalink)
King Adrock


 
 

BitmapSource Disposal/cleanup

I have a dispatchtimer pulling System.Drawing.Bitmap Images from my
webcam and I am displaying them on my WPF UI. I am using a
BitmapSource created by CreateBitmapSourceFromHBitmap using the
..GetHbitmap() method from my Bitmap object.

I am getting some serious memory leaks - besides setting my ImageSource
to null before assinging a new BitmapSource to it, is there anyway I
can dispose of the object?


My System SpecsSystem Spec
Old 07-25-2006   #2 (permalink)
robertwl@nospam.microsoft.com


 
 

re: BitmapSource Disposal/cleanup

You are likely leaking HBITMAPs. Are you doing something like this:

BitmapSource bmpSrc = null;

using(System.Drawing.Bitmap bmp = ...)
{
bmpSrc = System.Windows.Interop.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(),...);
}

?

If not, then you're leaking HBITMAPs from the System.Drawing.Bitmap. Those need to be disposed after using them.

-----Original Message-----
From: King Adrock
Posted At: Monday, July 24, 2006 4:31 PM
Posted To: microsoft.public.windows.developer.winfx.avalon
Conversation: BitmapSource Disposal/cleanup
Subject: BitmapSource Disposal/cleanup


I have a dispatchtimer pulling System.Drawing.Bitmap Images from my
webcam and I am displaying them on my WPF UI. I am using a
BitmapSource created by CreateBitmapSourceFromHBitmap using the
..GetHbitmap() method from my Bitmap object.

I am getting some serious memory leaks - besides setting my ImageSource
to null before assinging a new BitmapSource to it, is there anyway I
can dispose of the object?
My System SpecsSystem Spec
Old 07-25-2006   #3 (permalink)
King Adrock


 
 

Re: BitmapSource Disposal/cleanup

I've made the changes you've shown me but I'm still leaking memory.
Here is a snippit of code form my app - this is running at 30fps and I
update whenever I receive a new frame from my Video Camera

using( System.Drawing.Bitmap bmp = IMGManager.MainBitmap )
{
if (vidMain.Fill == null)
{
vidMain.Fill = new
ImageBrush(System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(),
IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
}
else
{
ImageBrush bmpSrc = vidMain.Fill as ImageBrush;
BitmapSource bsrc = bmpSrc.ImageSource as BitmapSource;
bsrc = null; //no dispose method.. how do i clean up?
bmpSrc.ImageSource =
System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(),
IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
}
}

I see a post on the MSDN forums quoting a simmilar issue - Our issue is
there is no visible way of manually disposing of the interopbitmapsouce

http://forums.microsoft.com/MSDN/Sho...23409&SiteID=1


robertwl@nospam.microsoft.com wrote:
> You are likely leaking HBITMAPs. Are you doing something like this:
>
> BitmapSource bmpSrc = null;
>
> using(System.Drawing.Bitmap bmp = ...)
> {
> bmpSrc = System.Windows.Interop.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(),...);
> }
>
> ?
>
> If not, then you're leaking HBITMAPs from the System.Drawing.Bitmap. Those need to be disposed after using them.
>
> -----Original Message-----
> From: King Adrock
> Posted At: Monday, July 24, 2006 4:31 PM
> Posted To: microsoft.public.windows.developer.winfx.avalon
> Conversation: BitmapSource Disposal/cleanup
> Subject: BitmapSource Disposal/cleanup
>
>
> I have a dispatchtimer pulling System.Drawing.Bitmap Images from my
> webcam and I am displaying them on my WPF UI. I am using a
> BitmapSource created by CreateBitmapSourceFromHBitmap using the
> .GetHbitmap() method from my Bitmap object.
>
> I am getting some serious memory leaks - besides setting my ImageSource
> to null before assinging a new BitmapSource to it, is there anyway I
> can dispose of the object?


My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Cleanup after SP1 -- Using recovery DVD Vista General
Disk Cleanup Bug Vista performance & maintenance
disk cleanup Vista performance & maintenance
Problem creating an BitmapSource from an HBitmap in threaded code .NET General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46