• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Grabage Collection help

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When will the variable Str be eligible for garbage collection.
public class MyClass{
public static void main(String[] args({
String s = "AString";
s = null; // Line 1
}// Line 2
At line 1 or line 2.
I thought it should be line 1.
But as per the Sun exam, it is at line 2 after the method call ends.

Any explainations.
Thanks.

}
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I think the object is eligible for garbage collection AFTER
line 1 is executed. That is why the answer would be line 2.
Do you agree ?
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all..
well i also think the correct answer is 1) .. the only reason 2) might be given as correct would have something to do with the compiler maintaining constant strings in the string pool in which case they are GCed after the method returns..
i remember reading in one of the posts that such a GC consideration is implementation dependent.. therefore i am not completely sure about this ques..

------------------
Hima
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Continuing this thread on GC ,can somebody help me selecting correct ans on GC
Which of the following statements related to Garbage Collection are correct.
Select all correct answers.
A.It is possible for a program to free memory at a given time.
B.Garbage Collection feature of Java ensures that the program never runs out of memory.
C.It is possible for a program to make an object available for Garbage Collection.
D.The finalize method of an object is invoked before garbage collection is performed on the object.
in my opinion,it should be a,c,d
need help!!
thank you
 
sajida kal
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think c and d is correct. As for a, it seems incorrect to me.
It is not possible for the program to free memory by itself.
At most it can make objects available for garbage collection by assigning them to null or it can invoke System.gc(). But there
is no guarantee that garbage collection thread will run.
If the option was framed such that it said -the program
can make objects available for garbage collection, then we could select this option.
Any other opinions on this ?
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The correct answers are
C.It is possible for a program to make an object available for Garbage Collection.
D.The finalize method of an object is invoked before garbage collection is performed on the object.

------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the correct answers are b(which is the primary use of GC) and d(This is because finally is executed no matter what happens unless, there is a deliberate shut off by someone).

Originally posted by preeti dengri:
Continuing this thread on GC ,can somebody help me selecting correct ans on GC
Which of the following statements related to Garbage Collection are correct.
Select all correct answers.
A.It is possible for a program to free memory at a given time.
B.Garbage Collection feature of Java ensures that the program never runs out of memory.
C.It is possible for a program to make an object available for Garbage Collection.
D.The finalize method of an object is invoked before garbage collection is performed on the object.
in my opinion,it should be a,c,d
need help!!
thank you


 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic