手动清理垃圾测试
Posted 范仁义
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了手动清理垃圾测试相关的知识,希望对你有一定的参考价值。
手动清理垃圾测试
1 package com.fry.FinalizeTest; 2 3 public class FinalizeTest extends java.lang.Object{ 4 @Override 5 protected void finalize() throws Throwable { 6 // TODO Auto-generated method stub 7 super.finalize(); 8 System.out.println("The object is gone!"); 9 } 10 public static void main(String[] args) { 11 for(int i=1;i<=100;i++) { 12 new FinalizeTest(); 13 } 14 System.gc(); 15 System.out.println("The program is ending"); 16 } 17 }
当有14行的System.gc();时的运行效果:
The program is ending
The object is gone!
The object is gone!
The object is gone!
The object is gone!
The object is gone!
The object is gone!
The object is gone!
The object is gone!
The object is gone!
The object is gone!
The object is gone!
The object is gone!
The object is gone!
The object is gone!
The object is gone!
The object is gone!
The object is gone!
The object is gone!
当没有14行的System.gc();时的运行效果:
The program is ending
以上是关于手动清理垃圾测试的主要内容,如果未能解决你的问题,请参考以下文章