#101 Destructor COM object never is called with DispatchEvents

1.16
closed-fixed
nobody
Jacob COM (35)
5
2012-10-20
2011-09-22
No

When a DispatchEvent is created with a COM object, the COM object is never released totally, and the destructor function is never called.

The problem is because when a DispatchEvent is associated with a COM object, an EventProxy object is created, that increment the reference number when is called its method Connect. After DispatchEvents is released, the EventProxy method is not deleted directly, a Release method is called, but the reference count of EventProxy never reachs 0 because Discconect never has been called. Disconnect call, is inside the destructor funtion of EventProxy and never is called.

I have found two solutions:

- The first solution is to delete the EventProxy directly:

JNIEXPORT void JNICALL Java_com_jacob_com_DispatchEvents_release
(JNIEnv *env, jobject _this)
{
EventProxy *ep = extractProxy(env, _this);
if (ep) {
// this is the line that blows up in IETest
// ep->Release(); // Old code
delete ep; // New Code
putProxy(env, _this, NULL);
}
}

- The second solution is to call disconnect before the release of EventProxy, although modify to public is need to the method Disconnect:

JNIEXPORT void JNICALL Java_com_jacob_com_DispatchEvents_release
(JNIEnv *env, jobject _this)
{
EventProxy *ep = extractProxy(env, _this);
if (ep) {
// this is the line that blows up in IETest
ep->Disconnect(); // New Code
ep->Release();
putProxy(env, _this, NULL);
}
}

It is necessary to declare public the Disconnect function:

public:
void Disconnect();

Thanks in advance and best regards

Discussion

  • clay_shooter

    clay_shooter - 2011-10-01

    Which change do you think is cleaner?

     
  • clay_shooter

    clay_shooter - 2011-10-02

    How did you did you find this problem. What were the symptoms

     
  • clay_shooter

    clay_shooter - 2011-10-02
    • status: open --> open-accepted
     
  • clay_shooter

    clay_shooter - 2011-10-02

    This will show up in 1.16 M1 but I'd still like to understand how you found this.

     
  • Mariano Quesada

    Mariano Quesada - 2011-10-02

    I found the problem when I tried to access to my own COM object with JACOB and associated an event. I found that the destructor of my COM object was never called because its reference counter never reached 0. If you want to find the problem you must use a COM object implemented by yourself.

    I think that the cleanest solution is to declare public the Disconnect method.

     
  • clay_shooter

    clay_shooter - 2011-12-06
    • milestone: 940660 --> 1.16
    • status: open-accepted --> closed-accepted
     
  • clay_shooter

    clay_shooter - 2012-10-20
    • status: closed-accepted --> closed-fixed
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks