classafFancom::ComThread
sys::Obj afFancom::ComThread
Handles the tricky business of COM threading.
Every time a Fancom Variant is created, a doppelganger is created in COM land. While the JVM Garbage Collector does a good of cleaning up the Fancom Variants, there is no similar mechanism to clean up the Variants in COM land.
Instead, JACOB holds references to these COM Variants, on a per thread basis, in a Running Object Table (ROT) and only destroys them upon a manual call to ComThread.release.
(To do a proper job of this requires a finer grained control of the ROT - so some main classes, like SpInProcRecoCtx, don't get cleaned up and continue to fire events. The rest of the code (including Event Code) could then be run in a closure to release all objects created within. But this needs JACOB to be modified.)
In essence, call initSta()
at the start of your COM calls and release()
at the end.
For more details:
- See COM Apartments in JACOB from JACOB
- See The Least You Need to Know about COM from Groovy Scriptcom