Re: DispatchPtr not releasing

Morten Andersen <[email protected]> Tue, 6 Sep 2005 22:32:43 +0200
Newsgroups gmane.comp.windows.devel.jawin
Message-ID <[email protected]>
Hi Normand,

Normand Mongeau wrote:

> It's not easy to post code. I'll try to explain more in depth.
>
> DispatchPtr instances are kind of "smart" instances, because somewhere deep
> in the machinery of COM a Release gets sent when instances go out of scope.
> This is easily verified with the following: create a COM class, and
> implement a FinalRelease method just to track when it gets called.  So if
> you have code like this:
>
> instA = new A().
>
> when the instA variable goes out of scope the FinalRelease method will get
> called automatically (it's called by the Release() method).

I will assume this is due to the reference count reaching 0. And if you
call this code through Jawin, and don't call instA.close() it will
happen from the finalize() of A (if it gets called).

But it is unclear for me whether you actually calls close()?

I assume you have read the section
http://jawinproject.sourceforge.net/jawinuserguide_dispatch.html#dispatchptr_usage

> My problem is that if I need to pass the A instance to another COM class,
> the A never gets finalized.  This is also easy to verify with code like
> this:
>
> instA = new A().
> instB = new B().
> instB->invokeSomeMethodPassingTheOtherInstance(instA).
>
> the finalization of the B instance will happen, but not the finalization of
> the A instance.
>
> This only happens through JAWIN.  It's as if an extra refCount was added to
> the A instance, thus not releasing it.

I haven't verified whether you are correct. But what happens if your
java code is extended to:

instA = new A().
instB = new B().
instB->invokeSomeMethodPassingTheOtherInstance(instA).

instB.close();
instA.close();

Hope this helps you.
Best Regards
Morten