Question my ShellExtThumbnail dll not dispose

sinaone1

Member
Joined
Nov 26, 2011
Messages
10
Programming Experience
5-10
hi everyone
i created a thumbnail dll for my file type
my class dll create thumb for my files type but my class no dispose after create thumbnail
this is my project :
HPTShellExtThumbnailHandler.rar
what's my problem
thank you
 
For reference, in this thread you are working with VBShellExtThumbnailHandler sample from CodePlex. For example found in "All-In-One Code Framework (Windows Shell)" here Microsoft All-In-One Code Framework

At a quick glance I see you have this code:
Dim BmpOriginal As New Bitmap(Byte2Image(fsContent))
Byte2Image loads and returns an Image. This Bitmap constructor creates a copy of the Image argument, original is left as is. Later you dispose BmpOriginal, but the original image returned by Byte2Image has not been disposed, and will not until Image at some point is finalized.
 
Dispose the Image object returned by Byte2Image method.
In addition I would dispose the _stream provided by Initialize when done with it, that would be my though at least, since it is open and has been read.
I would also not dispose bmp_dest in GetThumbnail method, this is the Bitmap object returned to shell by handle (GetHbitmap).
 
Now you do this:
Dim BmpOriginal As New Bitmap(Image.FromStream(New MemoryStream(fsContent)))
You are still not disposing the original that you provide to Bitmap constructor. You need to dispose the object that Image.FromStream returns. You are familiar with variables, so use a variable. Assign the object from Image.FromStream to a variable, use it for Bitmap constructor, then dispose it. Same for MemoryStream, it is disposable so dispose it. Neither of those will not lock the file, though, since the source is a byte array, and not a file stream directly. From my test in Vista I do not get a file lock using this preview handler.
I would still not dispose bmp_dest since that is the image you are serving as preview, it can not be read by shell until your code is finished.

One improvement you can do is to load the stream data in Initialize method and dispose the source stream right away. This might cause any possible file lock to be released earlier.
 
Back
Top