Home All Groups Group Topic Archive Search About

Dispose on Kill process

Author
28 Nov 2006 4:35 AM
Mike Carlisle
Hi,

Is it possible to catch event when a .net application process is killed in
order to do the required cleanup? ie. task manager - kill process.

The only way I can think of doing this currently is by using windows
messages to catch the destroy message. From what I've read CLR doesn't appear
to be notified when this happens.

Is there an alternative, and is it possible that not disposing can lead to
memory leaks? I'm investigating an issue where this appears to be happening.
Although the process is killed it looks like some components are still in
memory (not confirmed)

Thanks,

Mike

Author
28 Nov 2006 5:10 AM
Peter Duniho
"Mike Carlisle" <MikeCarli***@discussions.microsoft.com> wrote in message
news:E2391F52-0813-4B03-8923-DD1CD5B27B91@microsoft.com...
> Is it possible to catch event when a .net application process is killed in
> order to do the required cleanup? ie. task manager - kill process.
>
> The only way I can think of doing this currently is by using windows
> messages to catch the destroy message. From what I've read CLR doesn't
> appear
> to be notified when this happens.

No one is.  When you kill a process, it's not permitted to execute any more
code.  Windows itself will do some cleaning up, but any code in the process
being killed is no longer eligible to be run.  That's what killing a process
is all about.

> Is there an alternative, and is it possible that not disposing can lead to
> memory leaks? I'm investigating an issue where this appears to be
> happening.
> Although the process is killed it looks like some components are still in
> memory (not confirmed)

I'm not entirely sure about that.  There are certain kinds of event handlers
that are documented as having to be removed on exit explicitly, otherwise
some global system resources are lost.  It may be that when a process is
killed, these resources do get lost.  But the kinds of events that fall into
that category are far and few between.  Even if that was a potential
problem, only certain, unusual programs would run into it.

That said, killing processes to stop them isn't a good idea.  It's a last
resort, and not just because you might leak some memory.  Killing a process
ought to be an abnormal situation, and happen infrequently enough that
rebooting the computer is a reasonable solution to any memory leaks that
might occur.

Pete

AddThis Social Bookmark Button