Exercise 3: Why Skipping .Quit() Leaves EXCEL.EXE Running — Possible Solution ==================================================================== WHY COM CLEANUP ISN'T AUTOMATIC ------------------------------ Per this chapter, a managed .NET object's memory is cleaned up automatically by the garbage collector once nothing references it anymore - every other object covered in this chapter benefits from that automatic cleanup with no extra effort required. COM predates .NET entirely and sits outside that managed system - a COM object doesn't get the same reliable, prompt automatic cleanup. The underlying native application process (EXCEL.EXE) that New-Object -ComObject Excel.Application actually launched keeps running as its own independent operating-system process, and .NET's garbage collector has no reliable, prompt mechanism for telling that separate native process to shut down just because a PowerShell variable referencing it went out of scope. WHY IT PERSISTS EVEN AFTER THE SCRIPT ENDS AND $excel GOES OUT OF SCOPE ------------------------------ $excel going out of scope only means the PowerShell VARIABLE referencing the COM object is gone - it does not mean the actual EXCEL.EXE process it was pointing at has been told to close. Per this chapter, that's the caller's own explicit responsibility, via .Quit() (and/or Marshal.ReleaseComObject()), not something that happens automatically as a side effect of the script ending or the variable disappearing. Without ever calling .Quit(), nothing ever instructs EXCEL.EXE to actually terminate, so it keeps running invisibly in the background indefinitely - one ghost process left behind per script run that skipped this step. WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly explains that COM objects fall outside .NET's automatic garbage collection, correctly distinguishes a PowerShell variable going out of scope from the underlying native process actually being told to close, and correctly identifies .Quit() as the explicit step that's required and was skipped.