I am noticing a strange behaviour with TOpenPictureDialog.
When creating and executing a TOpenPictureDialog, 13 threads are created, and when the dialog is destroyed, the threads remain present according to Windows Activity Monitor, except of 1 thread, which disappears.
Why is this happening?
The code I am using is the following:
var opd: TOpenPictureDialog;
begin
opd := TOpenPictureDialog.Create(self);
opd.Execute;
if opd.FileName = '' then exit;
opd.Free;
begin;
I am using Delphi XE2 with Windows 8.1
TOpenPictureDialog
does not create any threads of its own. They are all internal to the OS Shell, and they are cached and reused by the Shell as needed. You have no control over them, nor should you be worrying about them. Let the Shell do its job.
BTW, your code is not freeing the dialog if it is canceled or fails. Use a try/finally
block to avoid that:
var
opd: TOpenPictureDialog;
begin
opd := TOpenPictureDialog.Create(nil);
try
if not opd.Execute then Exit;
// use opd.FileName as needed...
finally
opd.Free;
end;
end;