• 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

Forcing GC to run

 
Ranch Hand
Posts: 71
2
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Les Morgan wrote:No, the garbage collector marks the items for disposal and then when it gets good and ready, then it will free up the memory. That has been an ongoing discussion and point of refactoring in the JVM for decades now.

When an object is dereferenced, then it will be "collected" and if you so desire you can at any point in your code request the GC to run, but in actuality, it will do it when it is ready to do so.



I was wondering if forcing the GC is a bad idea since it does this already-I think I was on stack overflow and saw an article that says you can do it but there are some cons:

Garbage Collector

and there was an article that explains how to do this.

Thanks,

Bill
 
Rancher
Posts: 975
23
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bill when you do that you go outside the JVM, and interface to a lower level gc routine, namingly the one in .NET which is MS's underpinnings in the OS. Most of us, at least in the old days, back around '99, ran to Java so we could escape MS's "DLL Hell", actual real technical therm for the era specific features of MS OS's, and enter the platform independent coding that Java offered. I am surprised that the person that presented that solution in stackoverflow wasn't flamed from the gallery.

So yes, if you escape Java's VM and hit the platform specific underpinnings in the OS, you may get the gc to run on command, but if you want to be in that control, then IMO, you are using the wrong language because it's just not Java's philosophy.

Bill foster wrote:

Les Morgan wrote:No, the garbage collector marks the items for disposal and then when it gets good and ready, then it will free up the memory. That has been an ongoing discussion and point of refactoring in the JVM for decades now.

When an object is dereferenced, then it will be "collected" and if you so desire you can at any point in your code request the GC to run, but in actuality, it will do it when it is ready to do so.



I was wondering if forcing the GC is a bad idea since it does this already-I think I was on stack overflow and saw an article that says you can do it but there are some cons:

Garbage Collector

and there was an article that explains how to do this.

Thanks,

Bill

 
Being a smart alec beats the alternative. This tiny ad knows what I'm talking about:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic