• 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
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Garbage collect from javaprepare.com Exam

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the following are correct related to Garbage Collection. Select all correct answers.
a. It is posible 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 fialize method of an object is invoked before garbage collection is performed on the object.
The answer given is b,c. But I choose b, c and d. B'case if the finalize method exist then it will be invoked right???
help me pls.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone pls. explain me??
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think garbage collection ensures that your program never runs out of memory. You can code in such a way that you leave references to objects but don't use those objects anymore. Garbage collection can act on only objects that do not have any references.
Regarding the finalize method...to my knowledge, finalize method will be called (if it exists) before removing the object. However if you resurrect your object reference in finalize method then the finalize method will not be called again when u remove the reference to the object later. So, finalize method is called only once for an object.
I am really not sure if I would not select answer d. Inspite of the above scenario, my instinct would be to select d. I am also interested in knowing what others think about this.
satish
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to Exam Cram by Bill Brogden ,
"If your class definition declares an instance method that overrides finalize() method, the JVM will run the method after it has decided that an object is eligible for reclamation, but before reclaiming the memory used by the object"
The above statement sounds like it happens only when the finalize() method is overridden.
 
Ranch Hand
Posts: 103
Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IMHO, answers c and d r correct, Garbage Collection of java will not ensure that, program will never run out of memory. And finalize method will be invoked before GCing the object.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
So you are all accepting that ans 'd' is correct. I am pretty sure that ans 'b' is correct. B'cas I read somewhere in this discusion that JVM ensures that the program never runs out of memory.
The program should not go out of memory that is why the automatic garbage collection runs in the backround with low-priority. But if you keep on creating objects and make those objects available for GC. If GC never gets a chance to run at that time your memory will keep on gets occupied, at some stage the GC will identify this situation and the GC will start run and our program will not run at that time.
The above concept I read somewhere not 100% sure. Please any one can help us. Planning to take exam on coming weekend.
Pls, pls. help us.
Thanks in advance.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surya,
A program can indeed run out of memory. Though the garbage collector will be eventually run by the JVM, there is no guarantee your program will not get impoverished of memory.
Perhaps that's why OutOfMemoryException exists
Ajith
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe the answer has been corrected on the website. The correct answer is c,d.
 
How do they get the deer to cross at the signs? Or to read this tiny ad?
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic