开发者

What happens to open handles when an application crashes? (Windows XP onwards)

开发者 https://www.devze.com 2022-12-21 09:21 出处:网络
I was under the impression that if an application has an open handle and it crashes, the handle isn\'t released and if you开发者_JS百科 try to access that handle (let\'s say of a file) then you would

I was under the impression that if an application has an open handle and it crashes, the handle isn't released and if you开发者_JS百科 try to access that handle (let's say of a file) then you would get an error.

However, I have tried this in Windows XP onwards and the handle seems to get released if I close the exe from task manager, before it has closed the handle. Following is the code:

Private Sub Form_Load()
    Dim iFile As Integer
    iFile = FreeFile          
    Open "myfilelock" For Output Lock Read Write As #iFile
    MsgBox "About to close" 'close it here with task manager

    Close #iFile

End Sub

So, does Windows XP onwards release all the open handles in case the exe having those handles crashes?


All versions of Windows close kernel handles when an application crashes. Even Windows 95 did this. And certainly anything based on the Windows NT kernel or later will close kernel handles on an app crash.

This includes handles to files, events, semaphores, shared memory, pipes and sockets


All modern OS's clean up all program resources when a program exits or crashes -- memory, handles, sockets, threads, etc. Otherwise you would get massive resource leaks from each handle that an app developer forgot to close on exit, and have to periodically reboot your computer...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号