• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Garbage Collection, which line?

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

On which line would 'str' be garbage collected?
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On which line would 'str' be garbage collected?
If you mean the String object created on line 5 created with new, when it would be eligible for garbage collection, that would be line 8 because at that point there are no longer any reachable references to it. Of course you realize that two String objects are created on line 5, one of which will not be garbage collected because it is placed in the pool of String literals.
[ March 02, 2004: Message edited by: Michael Morris ]
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Morris:
[b]Of course you realize that two String objects are created on line 5, one of which will not be garbage collected because it is placed in the pool of String literals.


Keep in mind that the String literal pool (and modifications to garbage collection because of it) are not on the SCJP exam.
 
What's a year in metric? Do you know this metric stuff tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic