PrepAway - Latest Free Exam Questions & Answers

Which two actions should you perform?

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.)

PrepAway - Latest Free Exam Questions & Answers

A.
Use a class destructor that is called from within the Dispose method.

B.
Implement the IDisposable interface.

C.
Inherit from the WeakReference class.

D.
Use a class destructor that calls the Kill method.

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.

Cleaning Up Unmanaged Resources

One Comment on “Which two actions should you perform?


Leave a Reply