• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JQ+ Garbage Collection

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic