Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • 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
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Regarding Garbage Collection (was Regarding Threads)

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the following is true ??

1)An object will be garbage collected when it becomes unreachable

True : When object is not reachble its eligible for GC right

2) An object will be garbage collected if it has null assigned to it

false

3) The finalize method will be run before an object is garbage collected.

true : finalize method will be atleast once..

4) Garbage collection assures that a program will never run out of memory

false..GC does not assure
[ December 01, 2006: Message edited by: Barry Gaunt ]
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Suguna Gollapally:
...1)An object will be garbage collected when it becomes unreachable

True : When object is not reachble its eligible for GC right

2) An object will be garbage collected if it has null assigned to it

false...


I would answer "false" to number one. Yes, an object is eligible for GC when it is no longer reachable, but the question asks whether it will be collected, and that is not guaranteed.

Question two is a little peculiar. You don't assign null to objects -- you assign null to variables that might otherwise reference objects. Now, if the question said something like, "An object will be garbage collected if any reachable references to it are replaced with null references..." Well, even then we would be back to the situation in question one. It would be eligible, but not necessarily collected.

I'm curious: Where are these questions coming from?
[ December 02, 2006: Message edited by: marc weber ]
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
3) The finalize method will be run before an object is garbage collected.

true : finalize method will be atleast once..
My answer:
false : finalize() mehod will run once before the object is about to GCed, later it may or may not be GCed.So if the finalize() method has already runned for an program then it will not run again though the objects may be GCed again.
 
An elephant? An actual elephant. Into the apartment. How is the floor still here. Hold this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic