Java 类加载器和内存管理
Java classloader and memory management
当classloader加载classA
时,classes将被classloader加载,在哪个内存位置JVM会放这些对象吗?如果 flag
是 false
是否会加载 class D
?
public class A {
B b = new B();
C c = null;
static int i;
int j;
public static void main(String args[]) throws Exception {
boolean flag = true;
if (flag) {
m1();
}
A a = new A();
a.m2();
}
private static void m1() {
D d = new D();
d.print();
}
private void m2() {
c = new C();
System.out.println("inside m2");
}
private static void m3() {
System.out.println("inside m3");
}
}
Which all classes will be loaded by classloader
A
和 Object
作为最小值。根据实现的不同,JVM 可能会在 class 初始化或创建第一个实例时加载 B
和 C
。在调用 m2()
之前,可能不会初始化 C
。
in which memory location in JVM these objects would be put
不管你用哪个ClassLoader,小对象都放在伊甸园space
If flag is false will class D be loaded
可能不是,但这取决于 JVM。
当classloader加载classA
时,classes将被classloader加载,在哪个内存位置JVM会放这些对象吗?如果 flag
是 false
是否会加载 class D
?
public class A {
B b = new B();
C c = null;
static int i;
int j;
public static void main(String args[]) throws Exception {
boolean flag = true;
if (flag) {
m1();
}
A a = new A();
a.m2();
}
private static void m1() {
D d = new D();
d.print();
}
private void m2() {
c = new C();
System.out.println("inside m2");
}
private static void m3() {
System.out.println("inside m3");
}
}
Which all classes will be loaded by classloader
A
和 Object
作为最小值。根据实现的不同,JVM 可能会在 class 初始化或创建第一个实例时加载 B
和 C
。在调用 m2()
之前,可能不会初始化 C
。
in which memory location in JVM these objects would be put
不管你用哪个ClassLoader,小对象都放在伊甸园space
If flag is false will class D be loaded
可能不是,但这取决于 JVM。