您可以使用程序Process Explorer来查看运行应用程序的手柄数量。 有没有用Delphi代码来获取这个数字的方法? 我有兴趣跟踪应用程序本身的号码; 没有findProcess Explorer正在执行的其他应用程序使用的句柄数。
我的意图是让应用程序跟踪/检测可能的资源泄漏。
使用GetProcessHandleCount
函数。 这个API函数是由Winapi.Windows单元导入的最新版本的Delphi(所以你可以省略提出的):
function GetProcessHandleCount(hProcess: THandle; var pdwHandleCount: DWORD): BOOL; stdcall; external 'kernel32.dll'; procedure TForm1.Button1Click(Sender: TObject); var HandleCount: DWORD; begin if GetProcessHandleCount(GetCurrentProcess, HandleCount) then ShowMessage('Handle count: ' + IntToStr(HandleCount)); end;