When does the .NET garbage collector reclaim the memory of an object?
Correct answer D. When the object is no longer reachable from any root, at a time chosen by the runtime
The garbage collector frees objects that can no longer be reached from roots such as static fields, local variables on the stack and CPU registers. Collection is non-deterministic: it happens when the runtime decides, often when generation 0 fills up, not at the exact moment a variable goes out of scope. C# has no delete operator; deterministic clean-up of resources uses Dispose instead.
Answer checked How we write and check questions
Discussion