Monday, May 02, 2005

Transcender Question of the day

Related Exam: Microsoft 70-306 Developing and Implementing Windows-based Applications with Microsoft Visual Basic .NET and Microsoft Visual Studio .NET

You are writing a grade book application that will be used at small junior colleges. The institutions in your target market do not have a large budget for computer hardware, so most of their computers are older systems with limited resources.

Which of the following steps should you take to minimize resource requirements for the application?

a. Override the Finalize method. Within the overridden method, destroy and release all critical resources. Call the Finalize method just before setting the last of the object's reference variables to Nothing.

b. When you are finished with an object reference, explicitly destroy the reference by setting it to Nothing.

c. Implement the IDisposable interface. In the IDisposable.Dispose method implementation, destroy and release all critical resources. Call this method just before setting the last of the object's reference variables to Nothing.

d. Create a timer class. Set the timer to call the System.GC.Collect method once every minute to force the Garbage Collection process to run.


--------------------------------------------------------------------------------
Answer:
Taken from CERT-70-316
Related Exam: Microsoft 70-316 Developing and Implementing Windows-based Applications with Microsoft Visual C# .NET and Microsoft Visual Studio .NET

Choice c is correct. To minimize resource requirements for the grade book application, you should implement the IDisposable interface and, in the IDisposable.Dispose method implementation, destroy and release all critical resources. You should also call this method just before setting the last of the object's reference variables to null. The IDisposable interface provides a mechanism through which scarce resources can be released without waiting for the Garbage Collection process. The programmer must ensure that the Dispose method is called only when the last reference to an object is being destroyed.

The Finalize method is declared as protected and cannot be called from any code that is not a part of a child of the object. Setting the reference to null simply flags the object so that the Garbage Collector will destroy it and free its resources on its next pass. Forcing Garbage Collection to occur more frequently often results in a degradation of application performance.

References:

MSDN, Contents, ".NET Development," ".NET Framework SDK," "Product Documentation," "Reference," "Class Library," "System," "IDisposable Interface," "Methods," "IDisposable.Dispose Method."

No comments: