• Post Reply Bookmark Topic Watch Topic
  • New Topic

Forcing GC to run  RSS feed

 
Bill foster
Ranch Hand
Posts: 63
Java
  • Mark post as helpful
  • send pies
  • 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
 
Les Morgan
Rancher
Posts: 776
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!