Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • 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
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Garbage Collection

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

when r we using garbage collection? and finalize()?
we have to manually run it? Or, the system will do it automatically?
I feel confuse on this section, pls help
 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jini,


when r we using garbage collection? and finalize()?
we have to manually run it? Or, the system will do it automatically?
I feel confuse on this section, pls help


Well, a programmer NEED NOT to call the gc explicitely, because ,
the JVM will automatically call the gc once it is conviced that a particular object cannot be accessed. However, you can suggest the JVM to invoke the gc by calling the <code>system.gc() or Runtime.getRuntime().gc()</code>.
Same is the case for <code>finalise() </code> method. The API decalres that it is a protected method so in order to invoke this method you need to import java.lang.*; package.
This method is invoked when the a method is being is eligible for gc, the programmer can override the finalise() method, inorder to do some cleaning up. But, one thing must be borne in mind that the programmer should not assume that by calling the method will run the method at that point in time. So no judgement should be made on this point.
Hope this clears your doubt.
Ravindra Mohan.
[This message has been edited by Ravindra Mohan (edited May 30, 2001).]
 
jiny tee
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for ur reply Ravindra!!
I got a senario that might need ur help again
For example, i had written down a program which consists of finalize() method on 1/2/01. Some how, at 1/5/01 the gc is going to occur.
From my understanding, the finalize() method is called just before garbage colection. So, in this case... will the finalize() method that i created on 1/2/01 be executed on 1/5/01 ? (before the gc)
Pls enlighten me....

[This message has been edited by jiny tee (edited June 05, 2001).]
reply
    Bookmark Topic Watch Topic
  • New Topic