非静态方法中定义的变量将与对象一起被垃圾收集
will variables defined in non static method be garbage collected with object
class Utility{
public String a = "aaaa huge string";
public void doSomething() {
String b = "bbbb huge string";
.....
}
}
给定 class 实用程序,这是我的方法调用。
Step 1) Utility u = new Utility();
Step 2) u.doSomething();
Step 3) u = null;
当对象u在步骤3之后被垃圾回收时,字符串b是否也会从字符串池中移除?
何时从内存中加载和删除字符串 a 和 b(如果有的话)?
方法中定义的变量不是实例的成员,所以它们引用的对象的GC完全独立于实例的GC。
When object u is garbage collected after step 3
如果 对象 u
在第 3 步后被垃圾回收
will the String b also be removed from the String pool?
u
与b
无关:见上。
When will strings a and b be loaded and removed (if at all) from memory?
加载了 class,因为它们是字符串文字。移除取决于GC和实习。
class Utility{
public String a = "aaaa huge string";
public void doSomething() {
String b = "bbbb huge string";
.....
}
}
给定 class 实用程序,这是我的方法调用。
Step 1) Utility u = new Utility();
Step 2) u.doSomething();
Step 3) u = null;
当对象u在步骤3之后被垃圾回收时,字符串b是否也会从字符串池中移除?
何时从内存中加载和删除字符串 a 和 b(如果有的话)?
方法中定义的变量不是实例的成员,所以它们引用的对象的GC完全独立于实例的GC。
When object u is garbage collected after step 3
如果 对象 u
在第 3 步后被垃圾回收
will the String b also be removed from the String pool?
u
与b
无关:见上。
When will strings a and b be loaded and removed (if at all) from memory?
加载了 class,因为它们是字符串文字。移除取决于GC和实习。