• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Khalid & Rasmussen 's gc stuff.....

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Page 255 question 8.1, Khalid & Rasmussen.
e. If an object obj1 can access an object obj2 that is eligible for garbage collection, then obj1 is also eligible for garbage collection.
Can anyone explain with a few lines of code.
Thanks.
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If an object obj1 can access an object obj2 that is eligible for garbage collection, then obj1 is also eligible for garbage collection.
eram,
I have responded your previous post regarding GC. Please go through that. I think the author means this.

So the above statement is false
regds
maha anna

[This message has been edited by maha anna (edited March 18, 2000).]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, the statement is true. It's not talking about what happens if you set obj1's reference to obj2 to null. It's saying that assuming obj1 still has a reference to obj2, then the only way obj2 could be eligible for garbage collection is if obj1 is also eligible for collection. The fact that obj2 still has a reference from obj1 does not prevent collection if obj1 is not itself reachable from any active threads. Example:

After the last line, both Vectors are eligible for GC, even though they both still have references to each other - because neither Vector can be reached by any references in the code.
 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
before i begin i would just like to say... "great example Jim!"
well anyway i saw the title of eram's post and i think our question fits right in... so here it goes...
on page 255 of Khalid's and Rolf's book under the "Invoking Garbage Collection" section it is stated that:
"The System.gc() method can be used to force garbage collection..."
i have seen a couple of mock exams say that garbage collection can never be forced... we're a bit confused here.. help of any kind would be very much appreciated! thanks!
 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,... please check errata... author has changed it to request.

[This message has been edited by V Srinivasan (edited July 09, 2001).]
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not think the statement is generally true.
There are good example already by Maha.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi -

System.gc() cannot force the garbage collector to run it merely requests that the garbage collector runs.
I'm also under the impression that even though the gc runs and objects are eligible for garbage collection, there is no guarantee that the objects will be garbage collected - the gc thread could be interrupted by a higher priority thread and stop garbage collecting.
Den
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi eram,
Please read the JavaRanch Name Policy and re-register using a name that complies with the rules.
http://www.javaranch.com/name.jsp

Thanks for your cooperation.

------------------
Co-Moderator of the Programmer Certification Forums
reply
    Bookmark Topic Watch Topic
  • New Topic