• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

finalize()

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Under what circumstances, the finalize() method will not be called on an object? This is from JQ+ question ID :956415217580.
Thanks,
Jenny
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jenny.
Pls. give complete questions.
I believe JQ+ has options below each question & it states how many correct answers the question has.
The more precise you are with asking the questions, more the chances for a quick answer from the Ranchers.
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Himanshu's right - If we can see all of the choices, we can tell you which ones are right. Without seeing them, I'm sure I'd forget a sitution.
However, just off the top of my head, an object might not have its finalize() method invoked if the application exits prior to garbage collection occuring. That's one situtation. There may be more.
Corey
 
Jian Yi
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question ID :956415217580
Which statements describe guaranteed behavior of the garbage collection and finalization mechanism in java?
1. The Garbage Collector will never call finalize() more than once on an object.
2. The finalize() method will eventually be called on every object.
3. The garbage collector will use a mark and sweep algorithm.
4. An object will not be garbage collected as long as it is possible for an active part of the program to access it through a reference.
5. Objects are deleted when they can no longer be accessed through any reference.
why number 2 is not correct?
Corey, if what you said is true: "an object might not have its finalize() method invoked if the application exits prior to garbage collection occuring." Then this object won't be garbage collected. Then there will be a lot of such objects dangling somewhere. That sounds like a bad practice.
Thanks,
Jenny
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I'll take a shot at this one, although I don't have a ton of experience in this area. Someone please correct me if I say something incorrect.
When you start a Java application, the underlying OS starts the JVM so that the JVM can execute the application. Whenever your application creates a new object, the JVM allocates memory for it within its own "sandbox." If the application exits prior to the objects being garbage collected, the memory is cleared along with the JVM by the underlying OS.
That's my understanding of the process.
I hope that helps,
Corey
 
Jian Yi
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Corey,
So you are saying there is another way to clear the memory other than garbage collector. That is something new to me. Thanks for pointing that out.
-Jenny
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The garbage collection thread frees up memory inside the JVM. Don't forget that the JVM itself is running within the underlying OS. That OS has to have a way to reclaim memory. If it didn't, your OS wouldn't run very long until you ran out of memory and had to reboot (unless you had a few terabyte of memory, maybe ).
Corey
 
reply
    Bookmark Topic Watch Topic
  • New Topic