This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JQ+ Garbage Collection

 
Dominic Mack
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The answer listed is line 5.
I'm not sure if this question is refering to the object reference 'b' or the actual object "world !".
If it is refering to the object reference 'b', it seems to me that it would not be available for gc till the method returns.
If it is refering to the actual object "world !"...from other posts I've read, when a string object is created it is saved for use later on and used again if the same string is referenced in code. (I know I'm not using the correct terms, excuse me)

[This message has been edited by Dominic Mack (edited October 12, 2001).]
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dominic,

I'm not sure if this question is refering to the object reference 'b' or the actual object "world !".

Only objects are eligibile for garbage collection; not reference variables.

from other posts I've read, when a string object is created it is saved for use later on and used again if the same string is referenced in code.

It's true that String literal objects, like "world !" are stored in the string literal pool and are not eligible for garbage collection. The statement <code>String b = new String("world !");</code> actually results in two objects:

  • a string literal "world !" which is stored in the string pool, and
  • a new string object containing the unicode characters for "world !" stored in the general memory area or 'heap'

  • The reference variable 'b' would hold the memory address to the String object stored in the 'heap'.
    After line 5 in the example, no reference would be pointing to the 'heap' object so it would be eligible for garbage collection.
    Hope that helps.
    ------------------
    Jane Griscti
    Sun Certified Programmer for the Java� 2 Platform
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic