⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gctest1.java

📁 Java Op Processor java vhdl processor
💻 JAVA
字号:
package gctest;import joprt.RtThread;import com.jopdesign.sys.Const;import com.jopdesign.sys.GC;import com.jopdesign.sys.Native;// GCTest1// Tests if GC collects the garbage object. The GC is explicitly invoked.public class GCTest1 {	public static void main( String s[] ) {		new RtThread(20, 1000000) {			public void run() {				String allocStr = "Allocation problem!";				String refStr = "Reference problem";								Garbage garbage = new Garbage();				int prevId = garbage.id;				GC.gc();				int freeHeap = GC.freeMemory(); 				for (;;) {					if(freeHeap != GC.freeMemory()){						System.out.println(allocStr);					}          garbage = new Garbage();                              if((garbage.id-prevId)!=1){           	System.out.println(refStr);           	System.exit(-1);          }                    prevId = garbage.id;                              GC.gc(); //Remove the old garbage object                    					waitForNextPeriod(); 				}			}		};		RtThread.startMission();        		for(int i=0;i<10;++i){			RtThread.sleepMs(1000);		}		System.out.println("Test 1 OK");	}}class Garbage {	static int cnt = 0;	public int id;	public Garbage(){	  cnt++;	  id = cnt;		System.out.print("Garbage object id:");		System.out.println(id);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -