Skip to main content

QUESTION 2

You work as the application developer at Certkiller .com. You create a new class that uses unmanaged resources, but which still has references to managed resources on other objects.

You want users of the new class to be able to explicitly release resources when the class instance is no longer required.

What should you do next?

Choose the three actions which you should perform. Each correct answer presents only part of the complete solution.

 

A. Define the existing class so that it inherits from the WeakReference class.

B. Define the existing class so that it applies the IDisposable interface.

C. Create a new class destructor which calls methods on other objects to release the managed resources.

D. Create a new class destructor that releases the unmanaged resources.

E. Create a new Dispose method that calls System.GC.Collect to force garbage collection.

F. Create a new Dispose method that releases unmanaged resources and which also calls methods on other objects to release the managed resources.

 

Answer: B,D,F

 

Explanation: 

It is necessary to implement the IDisposable interface if you need to release unmanaged resources or want explicit control of the life of managed resources. A class destructor should be created to release the unmanaged resources and this should be called from

within the Dispose method. The dispose method should also release the managed resources.

Inheriting from WeakReference would result in the garbage collector releasing resources even though there may be valid references.

The managed resources should be released in the Dispose method.

System.GC.Collect could be used, however it is more efficient to manually release the managed resources. The GC incurs overhead and may have only recently been called anyway. The question states resources should be released explicitly.

Comments

Popular posts from this blog

Top Open Source Web-Based Project Management Software

This is an user contributed article. Project management software is not just for managing software based project. It can be used for variety of other tasks too. The web-based software must provide tools for planning, organizing and managing resources to achieve project goals and objectives. A web-based project management software can be accessed through an intranet or WAN / LAN using a web browser. You don't have to install any other software on the system. The software can be easy of use with access control features (multi-user). I use project management software for all of our projects (for e.g. building a new cluster farm) for issue / bug-tracking, calender, gantt charts, email notification and much more. Obviously I'm not the only user, the following open source software is used by some of the biggest research organizations and companies world wild. For example, NASA's Jet Propulsion Laboratory uses track software or open source project such as lighttpd / phpbb use re...

Google products for your Nokia phone

Stay connected with Gmail, Search, Maps and other Google products. Check products are available for your Nokia phone Featured Free Products Search - Find the information you need quickly and easily Maps - Locate nearby businesses and get driving directions Gmail - Stay connected with Gmail on the go YouTube - Watch videos from anywhere Sync - Synchronize your contacts with Google

DotNetNuke Overview

DotNetNuke is the leading Web Content Management Platform for Microsoft .NET. DotNetNuke can be used as a web content management system (CMS) for simple websites or as a powerful application development framework which enables businesses to quickly build and deploy feature-rich, interactive websites and applications in Microsoft .NET. An intuitive, menu-driven interface allows non-technical users to easily create new sites or extend the functionality and features of their existing web site when used as a web CMS. An open API and the availability of over 6,000 third-party add-on modules available through Snowcovered.com allow web development professionals to create complex web sites for demanding applications. Installing new modules or skins is quick and easy, allowing users to deploy new functionality on their web sites in just minutes. DotNetNuke is the world’s most widely adopted framework for building web solutions on Microsoft Windows Server. DotNetNuke powers o...