• 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

garbage collection

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi! in the following code, when we execute it, the finalize() method is called as the result of line 1 and 2. So should we assume that the behaviour of Runtime.getRuntime().gc() is certain?? One more thing if we use System.gc() instead of Runtime..then it doesn't call finalize().
thanx.
ashok.
________________
class best {
public void finalize() {
System.out.println("In finalize");
}
public static void main(String argv[]){
best e = new best();
e = null;
Runtime.getRuntime().gc(); //1
best e1 = new best();
e1 = null;
Runtime.getRuntime().gc(); //2
}
}
________________
 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am surprised with this behaviour especially because the API doc says the following:
The call System.gc() is effectively equivalent to the call:
Runtime.getRuntime().gc()

From the above statement one would assume that both the calls would behave in a similar way.
Any body any ideas....
Roopa

Originally posted by ashok khetan:
hi! in the following code, when we execute it, the finalize() method is called as the result of line 1 and 2. So should we assume that the behaviour of Runtime.getRuntime().gc() is certain?? One more thing if we use System.gc() instead of Runtime..then it doesn't call finalize().
thanx.
ashok.
________________
class best {
public void finalize() {
System.out.println("In finalize");
}
public static void main(String argv[]){
best e = new best();
e = null;
Runtime.getRuntime().gc(); //1
best e1 = new best();
e1 = null;
Runtime.getRuntime().gc(); //2
}
}
________________


 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I replaced the Runtime.getRuntime.gc() calls for System.gc() and the finalize methods are called as well.
The API clearly estates that the execution of the gc is not certain after calling the previous methods.
 
Roopa Bagur
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ashok,
I tried out your code..In both cases i.e when using System.gc() & Runtime.getRuntime().gc() finalize is called..

Originally posted by ashok khetan:
hi! in the following code, when we execute it, the finalize() method is called as the result of line 1 and 2. So should we assume that the behaviour of Runtime.getRuntime().gc() is certain?? One more thing if we use System.gc() instead of Runtime..then it doesn't call finalize().
thanx.
ashok.
________________
class best {
public void finalize() {
System.out.println("In finalize");
}
public static void main(String argv[]){
best e = new best();
e = null;
Runtime.getRuntime().gc(); //1
best e1 = new best();
e1 = null;
Runtime.getRuntime().gc(); //2
}
}
________________


 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
gc is never certain.
 
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic