Programming in C# — Question 139

You are developing an application by using C#.
The application includes an object that performs a long running process.
You need to ensure that the garbage collector does not release the object's resources until the process completes.
Which garbage collector method should you use?

Answer options

Correct answer: B

Explanation

The correct method is SuppressFinalize(), as it prevents the garbage collector from calling the finalizer for the object, thus ensuring its resources are not released prematurely. The other options do not serve this purpose: WaitForFullGCComplete() is for waiting on garbage collection, collect() forces garbage collection, and RemoveMemoryPressure() is used for managing memory pressure rather than preventing finalization.