Programming in C# — Question 146
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
- A. RemoveMemoryPressure()
- B. ReRegisterForFinalize()
- C. WaitForFullGCComplete()
- D. KeepAlive()
Correct answer: D
Explanation
The correct method, KeepAlive(), ensures that the garbage collector does not reclaim the resources of the specified object until after the operation has completed. The other options do not provide the same level of control over object lifetime in relation to garbage collection during long-running processes.