• 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

Garbage collection

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From Whizlab SCJP 1.4

Which of the following are true about garbage collection?
Select 2 options
1)You can directly free the memory allocated by an object.
2)You can directly run the garbage collector whenever you want.
3)The garbage collector informs your object when it is about to be garbage collected.
4)The garbage collector runs in low memory situation.

According to me option 2 for sure cannot be one of the answer. I think option 4 can be one of the answer.
Can someone kindly help me know which 2 options are right.
Thanks
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vidhya,

You are right about option 2 not being right, you can ask the JVM, but that never guarantees running of the GC! Option 1 is anyways ruled out!

Option 3 - As finally runs on the object before it is GCed, if that is what option 3 refers to, it has to be true!
Option 4 - True. As the topic in K&B states that the JVM already runs the GC before it gives you the OutOfMemory exception, which implies that GC is run in low memory conditions!

So looks like Option 3 and 4 are right, but option 3 kind of puts me into thinking regarding the underlying meaning that it has..!! Someone add to this please and correct me if I'm wrong!

Thanks,
Lakuma
[ September 30, 2008: Message edited by: Lakuma Yalamanchili ]
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lakuma,
Yes options 4 is obviously right. And even i say that the GC informs the object when it is about to be garbage collected. To be more clear GC will call the finalize() method of the object before that object is garbage collected. I think this is what option 3 means "informs your object".
 
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, Option 3 and 4 are right.

Garbage Collector cannot assure you that you will never run out of memory but assures you that whatever memory is availabe, will be managed effectively.
[ October 01, 2008: Message edited by: chander shivdasani ]
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
still there is one case when GC will not inform.Say GC has called the finalize method before garbage collecting, but in finalize method again you provide reference of that object to some other object. then GC will not collect that object .but later on when GC try to collect that object again ,it will not call finalize method again i.e. it call finalize method only once in object life time.
 
chander shivdasani
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, looking at the options, the first 2 can be easily eliminated. So,its the remaining two.
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
option 3 is so confusing

i think 3 & 4 are right
 
vidhya suvarna
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everybody.
[ October 01, 2008: Message edited by: vidhya suvarna ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic