views:

106

answers:

1

Is it possible to run .NET garbage collector from command line, e.g. without writing code?

+6  A: 

The garbage collector runs inside a process. So if you want to run the garbage collector for this process you could try the GC.Collect method. You cannot force garbage collection for a given process from the outside.

Also note that forcing garbage collection (using the GC.Collect) method is considered as bad practice and should be avoided.


There is no Microsoft tool and I have never heard of any 3rd party tool capable of doing this. Each process gets its own GC heaps, and therefore its own GC threads, so forcing a GC Collection on another process, AFAIK, is impossible.

Darin Dimitrov
Thanks, but as I asked in the question: "without writing code". I assume that there any tool, that I can call from command line for some specific process. So sorry, your answer is not relevant.
Kamarey
@Kamarey, there is no Microsoft tool (and I doubt any 3rd party tool exists). Each process gets its own GC heaps, and therefore its own GC threads, so forcing a GC Collection on anotherprocess, as far as I know, is impossible.
Darin Dimitrov
@Kamarey how is it not relevant stating no it can't be done and giving you the reason?
Rune FS
Ok, thanks. So can you replace your answer with your last comment, so it will answer my question?
Kamarey
@Rune FS: sorry, I don't get your english. Can you explain what the problem?
Kamarey
@Kamarey, updated answer to include my comment.
Darin Dimitrov