• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Can anyone help

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At what point is the object anObj available for garbage collection.
01: public class Base{
02:
03: private void test() {
04:
05: if(true) {
06: String anObj = "sample";
07: String locObj = anObj;
08: anObj.trim();
09: anObj = null;
10: locObj.trim();
11: }
12: }
13:
14: static public void main(String[] a) {
15: new Base().test();
16: }
17:
18: }
Select most appropriate answer
a) After line 7
b) After line 8
c) After line 9
d) After line 10
e) After line 11
please help:
thank
Yaco
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi:
I think the answer for your question is 'b' (After line 8). Immediately after line# 8, the 'anObj' reference has been assigned 'null', making the 'anObj' eligible for garbage collection.
Cheers,
Balu
 
Trailboss
Posts: 23247
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PROPER NAMES ARE NOW REQUIRED!
See http://www.javaranch.com/ubb/Forum10/HTML/000180.html for details.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't 'C' is the answer. Till line 9 object still alive only after that object looses its ref.
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At what point is the object anObj available for garbage collection.
01: public class Base{
02:
03: private void test() {
04:
05: if(true) {
06: String anObj = "sample";
I think the question really means at what point is the object referenced by variable anObj can be GCed. at line 6, an object reference variable of Type String is assigned a new String object which contains "sample". till line 10 this object is still reachable by the locObj reference variable.so it is only after the locObj goes out of scope in line 11 that the original object can be GCed.
Correct me if I am wrong.


 
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic