3 votes
Memory leak when using tabbed thumbnails


I use the code pack to display tabbed thumbnails, since I have a "tabbed document interface" type of application and want these tabs to be displayed as thumbnail windows (and .NET 4.0 does not support this). However, I noticed that I was leaking memory whenever the tabbed thumbnails were being displayed.

After some testing I finally found the reason: As part of DispatchSendIconThumbnailMessage(), the thumbnail bitmap is displayed via a call to DwmSetIconicThumbnail() with a scaled hBitmap. This object is not deleted if the original bitmap was supplied by the user.

However, the documentation in MSDN http://msdn.microsoft.com/en-us/library/dd389411(VS.85).aspx clearly states "The DWM uses a copy of the bitmap" and "The caller retains ownership of the original bitmap and is responsible for freeing the resources that it uses when it is no longer needed."

The solution is to always delete the hBitmap, i.e.:

TabbedThumbnailNativeMethods.SetIconicThumbnail(taskbarWindow.WindowToTellTaskbarAbout, hBitmap);

File Attachments

No files are attached


most recent at top (show oldest at top)
ynijsen wrote Mar 14 2011 at 1:12 PM
Occurs when consecutive calls are made to TabbedThumbnail.SetImage(myBitmap) methods.
The internal CurrentHBitmap should be destroyed first, before applying the new Bitmap....
This can also be resolved by calling SetImage(null) before applying your own image.

Page view tracker