Re: DispatchPtr not releasing
Normand Mongeau <[email protected]> Tue, 6 Sep 2005 16:52:10 -0400
| Newsgroups | gmane.comp.windows.devel.jawin |
|---|---|
| Message-ID | <016401c5b324$da23c8e0$6600a8c0@tocsh> |
Hi Morten, the plot thickens. > 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 don't call close() explicitely, no. If I do, the FinalRelease method of my COM object gets called immediately instead of when the java instance goes out of scope. > > I assume you have read the section > http://jawinproject.sourceforge.net/jawinuserguide_dispatch.html#dispatchptr_usage Yes I have, but it doesn't go into this level of detail. > >> 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(); When I add a call to instA.close() in the above scenario, the FinalRelease method of my COM object doesn't get called. I even tried several calls in succession to instA.close() but none of them result in my FinalRelease method being triggered. > > Hope this helps you. > Best Regards > Morten It helps in pinpointing the problem I guess... Thanks, Normand