Search code examples
javagarbage-collectionrmi

Java: a full GC when UnicastRemoteObject.exportObject() is called?


While researching on this question: Java: garbage collection for RMI target object? I saw that a full GC is triggered the first time I make this call:

UnicastRemoteObject.exportObject(new Remote(){}, 0);

I ran a very simple program containing the call above, with -verbose:gc set, and consistently saw that a full GC was triggered, e.g. [Full GC 1070K->184K(47552K), 0.0070096 secs]

I ran it through Eclipse, in command line, and on virtual and physical machines. I'm using Sun jdk and hotspot 1.6.

Has anybody observed similar behavior? What can be its cause?


Solution

  • There is a background thread which checks that the GC has been run in the java.rmi.dgc.leaseValue which defaults to one hour.

    If this is enabled before any GC has run, I suspect it will see this time since the last GC as too long and trigger a full gc.

    The class which does this is sun.misc.GC