由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - a garbage collection question
相关主题
Another garbage collection questionJava/J2EE的面试中,关于garbage collection的问题应该怎么回答?
折腾了一天,实在是绝望了,请教请教Core Java那两本砖头书太浅了
please help me to solve this question!help "java.lang.NoSuchMethodError"
Java都在什么时候进行Garbage collection?ask a spring framework question
Java里面可以暂时禁用Garbage Collection吗?问个题
Garbage collection 问题你们有人测试过这种语法么?
garbage collection issueFind maximum palindrome
size() method 为什么需要多线程保护?Re: help for running CPU intensive progr
相关话题的讨论汇总
话题: test话题: garbage话题: vector话题: string话题: collection
进入Java版参与讨论
1 (共1页)
s******e
发帖数: 63
1
public class A{
static Vector v = new Vector();
public void test{
String s = new String("Test");
v.put(s);
}
}
will s be garbage collected after running test method? assume garbage
collector runs concurrently.
w*r
发帖数: 2421
2
I wish some highhand can correct me if I were wrong, here is my understanding
s will be gone after test finish execution, however "Test" will stay
s is just a reference local to test() method.(assume you mean public
void test(){...}) , therefore this reference will be gone once the method
finish execution and exit its execution stack. s is not collected by
GC in this case. ...

【在 s******e 的大作中提到】
: public class A{
: static Vector v = new Vector();
: public void test{
: String s = new String("Test");
: v.put(s);
: }
: }
: will s be garbage collected after running test method? assume garbage
: collector runs concurrently.

g*****g
发帖数: 34805
3
It's not gonna be GCed as the Vecotor keeps an ref to the string.
It will be GCed only when v is GCed, that will be end of progam
as v is static.
Vector, memory pool, resource conn (DB, network) is where you 'll
find memory leak in Java.

【在 w*r 的大作中提到】
: I wish some highhand can correct me if I were wrong, here is my understanding
: s will be gone after test finish execution, however "Test" will stay
: s is just a reference local to test() method.(assume you mean public
: void test(){...}) , therefore this reference will be gone once the method
: finish execution and exit its execution stack. s is not collected by
: GC in this case. ...

1 (共1页)
进入Java版参与讨论
相关主题
Re: help for running CPU intensive progrJava里面可以暂时禁用Garbage Collection吗?
soft reference和weak reference的区别Garbage collection 问题
Singletongarbage collection issue
Re: 有用netbeans的吗?size() method 为什么需要多线程保护?
Another garbage collection questionJava/J2EE的面试中,关于garbage collection的问题应该怎么回答?
折腾了一天,实在是绝望了,请教请教Core Java那两本砖头书太浅了
please help me to solve this question!help "java.lang.NoSuchMethodError"
Java都在什么时候进行Garbage collection?ask a spring framework question
相关话题的讨论汇总
话题: test话题: garbage话题: vector话题: string话题: collection