• 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

About Garbage Collection

 
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I manage to get it wrong almost always in the mocks. I have read this from mughal and Marcus Green tutorial. But I am unable to solve questions based on this topic.
Can somebody guide me how to approach this topic and questions based on it confidently?
TIA,
- Manish
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
General guide lines:
G.C. cannot be forced only requested.
The G.C. doens�t prevent an OutOfMemoryError
.
The g.c. of an object is not guaranted.
The finalize method of an object will be only called (automatically) if the g.c. is running. It is not guaranted its execution though. However it is guaranted that if executed, it will be executed only once for an object, just before its memory is reclaimed. Also it is guaranted that if an object is recycled its finalized method has already been executed.
An object is eligable for g.c. if it is unreachable by all the reachable objects. This means that A is eligable for g.c. if there aren't any references to it, except from, for instance, from B object which is also unreachable.
Be careful with aliasing the objects. If two or more variables points to the same object, typical mock exams try to confuse by only seeting to null, or copying new values to them, to only some of the variables.
Just keep posting the Ranch the questions you find difficult in the mocks
[ March 17, 2002: Message edited by: Jose Botella ]
[ March 17, 2002: Message edited by: Jose Botella ]
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a MOUNTAIN of questions and answers on this very board about GC. Please try searching and reading those. I did quick look and over the last 3 days alone I found the following GC related posts.
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=24&t=015170
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=24&t=015218
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=24&t=015172
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=24&t=015183
Macon
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot, both of you
Also, I found this approach very useful -
1)Draw the object and references pointing to it on paper
2) Modify the references as per the code and examine if the object still has any valid ref., if not it *is* eligible for GC.
I managed to get both the GC questions correct in the last mock using this approach. Just thought I'll share it.
Regards,
- Manish
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic