• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is this right?

 
yun lou
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The garbage collector informs your object when it is about to be garbage collected
right or wrong?
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
right, by invoking ONCE the finalize method of your object.
From the Object API:

protected void finalize()
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
 
yun lou
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you! You are a really cool man! I will take the exam 16 Aug.
 
Younes Essouabni
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good luck for the exam!
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good luck Yun
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Val:
Quote from your note above:
right, by invoking ONCE the finalize method of your object.
From the Object API:

I think in first GC run, finalize will be
invoked and second GC run the object will be
cleared. Right?
Thanks
Barkat
 
Soum Sark
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the mark & sweep algorithm the first time it marks objects and then the second time it sweeps .. so any unmarked objects would be collected the second time ..pls correct me if i am mistaken
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neither the JLS nor the JVMS require the use of the mark & sweep algorithm for garbage collection. In fact, the choice of the algorithm is completely up to the JVM vendor. Thus, such assumptions cannot be made.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your finalize() method "resurrects" the object by making it reachable again, then the next time it becomes unreachable, the garbage collector will not call finalize() a second time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic