Garbage Collection and Reference Counting On Java Objects Referenced from COM Clients

When COM clients hold references to a Java object, the J-Integra® runtime maintains a reference inside the JVM to that Java object on behalf of the COM clients. It also keeps count of the number of COM references exported to that Java object and releases its reference when the COM reference count reaches zero. When running in DCOM, mode J-Integra® receives DCOM ping messages informing it that a COM client is still alive. If no such ping messages are received for six minutes (per the DCOM specification), the J-Integra® runtime releases all unpinged Java objects.

If you wish to be notified when Java objects are no longer referenced by COM clients, you can call the following method passing in a reference to an instance of a Java class you create that implements the com.linar.jintegra.Unreferenced interface:

com.linar.jintegra.Cleaner.addUnreferencedListener(com.linar.jintegra.Unreferenced listener)

The Unreferenced interface looks like this:

public interface Unreferenced {
public void objectUnreferenced(Object o);
}

When you no longer wish to be notified, call:

public static void removeUnreferencedListener(Unreferenced listener)

This is a small example:

public class MyJvm {
  public static void main(String[] args) throws Exception {
     com.linar.jintegra.Jvm.register("firstjvm");

     MyUnreferencedListener l = new MyUnreferencedListener();
     com.linar.jintegra.Cleaner.addUnreferencedListener(l);
        Thread.sleep(6000000); // Sleep for an hour
        com.linar.jintegra.Cleaner.removeUnreferencedListener(l);
  }
}
class MyUnreferencedListener implements com.linar.jintegra.Unreferenced {
  public void objectUnreferenced(Object o) {
     System.out.println("** Object no longer referenced: " + o);
  }
}