nerdexam
Microsoft

98-372 · Question #151

You create a class that uses unmanaged resources. You need to ensure that users of the class can explicitly release resources when the instance of the class is no longer required. Which two actions…

The correct answer is A. Implement the IDisposable interface. B. Use a class destructor that is called from within the Dispose method. To properly dispose of unmanaged resources, it is recommended that you implement a public Dispose or Close method that executes the necessary cleanup code for the object. The IDisposable interface provides the Dispose method for resource classes that implement the interface…

Understanding .NET Framework Concepts

Question

You create a class that uses unmanaged resources. You need to ensure that users of the class can explicitly release resources when the instance of the class is no longer required. Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)

Options

  • AImplement the IDisposable interface.
  • BUse a class destructor that is called from within the Dispose method.
  • CUse a class destructor that calls the Kill method.
  • DInherit from the WeakReference class.

How the community answered

(41 responses)
  • A
    80% (33)
  • C
    7% (3)
  • D
    12% (5)

Explanation

To properly dispose of unmanaged resources, it is recommended that you implement a public Dispose or Close method that executes the necessary cleanup code for the object. The IDisposable interface provides the Dispose method for resource classes that implement the interface. Because it is public, users of your application can call the Dispose method directly to free memory used by unmanaged resources. When you properly implement a Dispose method, the Finalize method becomes a safeguard to clean up resources in the event that the Dispose method is not called.

Topics

#IDisposable#Dispose method#destructor#unmanaged resources

Community Discussion

No community discussion yet for this question.

Full 98-372 Practice