• 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

Is Garbage collection always called at end of main ?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is "Finalize!!!" always printed or maybe not ?

I understand System.gc(); doesn't garantees the garbage collection to work, but the end of main doesn't it ? So in the case it does, the output always will be "Finalize!!!" ?

Thanks.


 
Ranch Hand
Posts: 310
1
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, there is no guarantee with GC even if you call System.gc() explicitly. finalize() may be called and it may NOT be called! That is why it is not advisable to put clean up code in finalize() method!
 
Leomar Espinal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rajeev Rnair wrote:No, there is no guarantee with GC even if you call System.gc() explicitly. finalize() may be called and it may NOT be called! That is why it is not advisable to put clean up code in finalize() method!



Yes, " there is no guarantee with GC even if you call System.gc()"

You are right, however I was asking also for the end of main.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, garbage collection is not automatically called at the end of the main() method.

(What would be the point? All of the memory is about to be given back to the operating system anyway, so why waste time organizing it for a JVM which will imminently stop existing?)
 
Leomar Espinal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:No, garbage collection is not automatically called at the end of the main() method.

(What would be the point? All of the memory is about to be given back to the operating system anyway, so why waste time organizing it for a JVM which will imminently stop existing?)



Ok, thanks paul.
I tested this:



And no Finalize!!! is shown, so that plus your explanation seems to be good enought, Thanks.

Solved.
 
No more fooling around. Read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic