-1
public class Test{
    public static void main(String... args){
        Test test = new Test();
        Class testClass = Test.class;
    }
}

As i know, if jvm want to GC Test class, it must meet below conditions:

  1. all instances of Test have already GC'ed.

  2. Test's class loader has GC'ed.

  3. Test cannot be reflected at anywhere(i am not sure about this condition)

so, my question are,

  1. does jvm need testClass object GC'ed or testClass GC after Test GC'ed?

  2. what situation class loader will be GC'ed

  3. explain more about condition 3

  4. does it enough of conditions which listed?

Tony
  • 351
  • 4
  • 16
  • 1
    That's 4 questions. Also, what version of Java? Are you familiar with perm gen space? – Elliott Frisch Sep 28 '15 at 14:20
  • yes, i know gen space, assume Java7 – Tony Sep 28 '15 at 14:21
  • It's in the [perm gen](http://stackoverflow.com/a/320469/2970947). When do you think permanents are garbage collected (and why)? – Elliott Frisch Sep 28 '15 at 14:47
  • yes, i know class is in perm gen, i make sure class can be garbage collected in extreme cases. eg: osgi or use a logs of dynamic proxy, they need to uninstall class sometimes – Tony Sep 28 '15 at 14:49

1 Answers1

-1

Class objects are constructed automatically by the Java Virtual Machine as classes are loaded and by calls to the defineClass method in the class loader.

Pradeep
  • 21
  • 6