How can I unit test GC?

For the project, we need a way to run custom scripts that can come with attached JAR files with additional classes.

What are my options when I want to write a couple of tests to make sure that a normal script leaves nothing behind?

I especially need to know: are all classes from attached JARs "offloaded"?

Note. I'm not looking for a 100% super waterproof solution that works in all versions of Java from 1.0 to 7. Right now, I just need to be better than β€œI have no idea”.

+5
source share
4 answers

, - , ( ).

, , , " ". , . , , . , , , .

, pure-Java, OSGi . OSGi .

+3

unit test . JVM -XX: -TraceClassUnloading , .

+3

, , .

WeakReference ClassLoader, JAR, script, System.gc() assertNull(reference.get())

+2

. ?

Java . ClassLoader , . , ClassLoader, ( ), ( ) GC, .

, , - . API, . , ClassLoader.

I see no way to fully automate testing for this. But I suppose you could track class unloading with any decent profiler.

+1
source

All Articles