Destructors for COM components

Posted on 2004-10-22
Last Modified: 2013-11-25
   I used the ATL COM wizard to create a component. I made an interface IDBManager. The implementation class is CDBManger. This class handles Database Operations. In the constructor of this class I've opened a few connections to databases. I want to release these connections when the component is killed....where do i write the code for the destructor itself? Or anywhere else?
Question by:manoj_johar
    LVL 12

    Expert Comment

    Destructor will do if you're only diong non-COM related stuff.

    Accepted Solution

    To do that you can override 'FinalRelease' on the ATL class your class is deriving from. From the ATL Library Reference:

    CComObjectRootEx::FinalReleaseSee Also
    CComObjectRootEx Overview | Class Members | CComObjectRootEx::FinalConstruct
    You can override this method in your derived class to perform any cleanup required for your object.

    void FinalRelease( );
    By default, CComObjectRootEx::FinalRelease does nothing.

    Performing cleanup in FinalRelease is preferable to adding code to the destructor of your class since the object is still fully constructed at the point at which FinalRelease is called. This enables you to safely access the methods provided by the most derived class. This is particularly important for freeing any aggregated objects before deletion.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Anonabox PRO Tor & VPN Router

    PRO is the most advanced way to fortify your privacy and online anonymity by layering the Tor network with VPN services. Use both together or separately, and without needing to download software onto your devices.

    For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
    A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    911 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now