• 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
  • Tim Cooke
  • paul wheaton
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
  • Himai Minh
Bartenders:

Garbage Collection

 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all
im preparing for the SCJP exam and would like to know how to find out when an object/variable is available for garbage collection .
This has been a problem for me because i can never say which line is the legal one for Garbage collection in the mock test that i have been giving .
please let me know
regards
pranav
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pranav,
The object is only available for Garbage Collection when there are no more references to that object. So
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is one of the beauties of java , u DONT HAVE TO WORRY ABOUT
GARBAGE COLLECTION 'COZ JVM TAKES CARE OF IT . We can not force gabage coll. we can only suggest by giving System.gc().
util there is a reference pointing to a object or the object is pointing to something it cant be garbage collected.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
how do we know that a reference is not pointing to some location
in the memory.
the simplest way to find out is when it equals null
eg.
Gc gc = new Gc();
gc=null;///after this line the object is not pointing anywhere
and is eligible for garbage collection.
but there are many other cases when the onject becomes eligible
for garbage collection..
can anybody please explian ...
sanjeev
 
I promise I will be the best, most loyal friend ever! All for this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic