permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage Collector" Watch "Garbage Collector" New topic
Author

Garbage Collector

Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
How many objects will be eligible for GC after the method returns?


the answer says only one ("a" in line 1) is garbage collected.
but what about line 2 and 3?


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
I have just found this:

The objects created in the String pool are not subjected to GC until the class is unloaded by the JVM. They get discarded at that time or just before the virtual machine unloads the class' bytecode.

Is that the reason why "str" in line 3 is not GCted?
Miki Muzsi
Ranch Hand

Joined: Jun 23, 2003
Posts: 120
but what about line 2 and 3?

line 2 declares a primitive variable, not an object! And the question is "How many objects will be eligible .... Anyway "i" is put on the stack so it gets deleted as soon as is out of the scupe (function in this case).
About String literals you already figured out the problem.
Miki


Miki<br /> <br />SCJP 1.4, SCBCD 1.3
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Andres, I have never read such a definitive statement about garbage collection and the string literals. I am curious to know the source of that statement. Marlene
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Marlene I do not know where Andres has read that, but this post is an example.


SCJP2. Please Indent your code using UBB Code
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Sorry guys for giving the wrong resource.. I was checking my notes and I found this statement here instead of JQplus.
 
Don't get me started about those stupid light bulbs.
 
subject: Garbage Collector
 
Similar Threads
Garbage collection?
garbage collection
Garbage Collection
how many eligible for Garbage Collection
What does it mean to be eligible for gc?