Jump to content
Developer Wiki and Function Reference Links ×

VCOM Interfaces: Release them or not? (refcount warning)


Stefan Bender

Recommended Posts

IN the constructor of one of our classes, we query for a VCOM interface:

 

 Boolean succ = VCOM_SUCCEEDED( ::GS_VWQueryInterface( VectorWorks::EnergyAnalysis::IID_EnergyBuildingElementWinDoorEx, (IVWUnknown**) & m_energy_2021 ) );

 

As requested in the SDK documentation, we release that interface in the destructor of the class:

 

if (m_energy_2021) {
        m_energy_2021->Release();
      //  m_energy_2021 = nullptr;
    }

 

Before releasing, the refcount (m_energy2021->fPtr) is 1, after releasing it is 0 which looks OK.

 

But after the end of the destructor, it seems that the VCOM destructor is called again, tries to release again and gives a debug warning saying refcount <0.

 

Is this OK? Should I release the interface by myself or wait for the automatic destructor? SDK doc says  I should release, but looking at the source code in various SDK plug-ins I get a mixed feeling, in some routines the interface is released, in others it is not.

 

What is the correct workflow? If I am supposed to release the interface by myself, why do I get the debug warning?

 

Thanks for any help,

 

Stefan Bender

 

Link to comment

Stephan,

 

Here's how I would tackle this:

 
class SomeClass
{
public:
    SomeClass();

private:
    IEnergyBuildingElementWinDoorExPtr m_energy_2021;
}

 

 

SomeClass::SomeClass() : m_energy_2021(IID_EnergyBuildingElementWinDoorEx)
{
    // If querying the interface fails for some reason, m_enery_2021 would be nullptr
}


The default destructor of SomeClass() will take care of releasing the acquired interface. Even if you create your own destructor, m_energy_2021 will still be released. So, to the best of my knowledge, there's no need for you to manually release it.


 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...