Dispose on Kill process

G

Guest

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
 
P

Peter Duniho

Mike Carlisle said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top