MSDN Archive Home
Help and FAQs
Windows® API Code Pack for Microsoft® .NET Framework
All Resource Updates
Create New Item
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/lib
rary/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.:
No files are attached
most recent at top
show oldest at top
Mar 14 2011 at 1:12 PM
Occurs when consecutive calls are made to TabbedThumbnail.SetImage(
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.
Close Work Item
Work Item Details
No Component Selected
Dec 8 2010 at 12:50 PM
Oct 8 2013 at 1:47 PM
Manage Your Profile
MSDN Flash Newsletter
© 2008 Microsoft Corporation. All rights reserved.