GabageCollection
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi, people!
Can anybody answer the question?!!
Can strings in the pool be eligible for gabage collection?
To answer that question try to answer the following one:
How many objects will be eligible for gabage collection after line //4?
String s1="string1"; //1
String s2=new String("string2");//2
String s3=s2.intern(); //3
s1=s2=s3=null;//4
Can anybody answer the question?!!
Can strings in the pool be eligible for gabage collection?
To answer that question try to answer the following one:
How many objects will be eligible for gabage collection after line //4?
String s1="string1"; //1
String s2=new String("string2");//2
String s3=s2.intern(); //3
s1=s2=s3=null;//4
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Yes, they can.
When the class loader that loaded the class containing the String literals is collected, the instances that were created at class load time are also (potentially) collected.
When the class loader that loaded the class containing the String literals is collected, the instances that were created at class load time are also (potentially) collected.
Tony Morris
Java Q&A (FAQ, Trivia)
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I think there is only one object eligible for GC after line 4.
As a reminder, the special issues involving the String Literal Pool will not be on the SCJP.
But it is a very interesting topic.
As a reminder, the special issues involving the String Literal Pool will not be on the SCJP.
But it is a very interesting topic.
Mike Gershman
SCJP 1.4, SCWCD in process
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
mike,
is the object originally referenced by s1 available for garbage collection? I didnt see the correct answer in your so was curious...
thx
is the object originally referenced by s1 available for garbage collection? I didnt see the correct answer in your so was curious...
thx
RB
posted 20 years ago
According to me, s1 is not available for garbage collection. Only string s2 is availabe. Its because s1 is being referred from the pool.
I have a code which i would like to discuss with u all:
This code gives varied output as u know everytime u run, but i have observed that output generated at line 1 is same as line 3.
But this is not the case with line 2 and line 4.
Does this gives us an idea that still "Ranch" is still being referred? and if thats the case then it means that "Ranch" is being referred from the pool.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
is the object originally referenced by s1 available for garbage collection?
According to me, s1 is not available for garbage collection. Only string s2 is availabe. Its because s1 is being referred from the pool.
I have a code which i would like to discuss with u all:
This code gives varied output as u know everytime u run, but i have observed that output generated at line 1 is same as line 3.
But this is not the case with line 2 and line 4.
Does this gives us an idea that still "Ranch" is still being referred? and if thats the case then it means that "Ranch" is being referred from the pool.
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
hi
i confused with the heap and pool of memory.
can i say that all the objects(using the new operator) will be created in the heap of memory and elegeble for the garbage collection.
the string objects created by mere assignment(String s="string") will be created in the pool of the memory which is not eligible for the garbage collection.
i confused with the heap and pool of memory.
can i say that all the objects(using the new operator) will be created in the heap of memory and elegeble for the garbage collection.
the string objects created by mere assignment(String s="string") will be created in the pool of the memory which is not eligible for the garbage collection.
Animesh Shrivastava
Ranch Hand
Posts: 298
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Please go thru this link for more idea on Strings.
String pool
String pool
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Yeah, this link gives a clear idea abt the how the string literals actually gets stored and when it gets available for garbage collection. 

Thanks,<br />Prabha
| Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |





