Java – intelligent garbage collection?

You simply call system GC () can do garbage collection in Java, but sometimes this "delays" the application Collecting garbage like this and avoiding stalling is a bad idea:

new Thread(new Runnable() {
   public void run() { 
      System.gc(); 
   }
}).start();

Or could this lead to more problems?

Solution

Yes, in most cases, call system GC () is a very bad idea There are a few exceptions, but they are rare. It's best to take the time to ensure that you don't do anything harmful to performance in the GC environment, and study and ensure that you understand how GC works instead of trying to deal with it explicitly calling system gc().

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>