I have global static registry in my class, which registering instances in some circumstances. Actually it does not depend on garbage collecting, but some functionality is obviously placed in finalize()
.
During jUnit test I wish to test how this functionality works, but I can't call GC by force. I am calling gc()
in my tearDown()
@After
public void tearDown() throws Exception {
log.debug("tearDown()");
a = null;
b = null;
c = null;
d = null;
e = null;
f = null;
g = null;
System.gc();
log.debug("asserting hash size");
assertEquals(0, Myclass.getRegisterSize());
}
but this does not help. I see in log that asserting message appears before finalizing.
Is it possible to wait until all finalizations occur?
Are there any other means, for example to restart classloader or flush heap or something in jUnit? I mean to do everything from scratch?