Practice mode C#

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

Explanation

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.