标签:string time() 手工 ++ start memory for dex row
public class Jichuleiku {
public static void main(String[] args) throws InterruptedException {
long start = System.currentTimeMillis();// 取得开始时间
Runtime run = Runtime.getRuntime();// 取得Runtime(单例设计模式)的实例化对象
System.out.println("1.MAX=" + run.maxMemory());// 返回最大可用内存空间
System.out.println("1.total=" + run.totalMemory());// 返回所有可用内存空间
System.out.println("1.free=" + run.freeMemory());// 返回空余内存空间,long是字节单位
String str = "";
Thread.sleep(3000);// 休眠3秒
for (int x = 0; x < 3000; x++) {
str += x;// 产生大量垃圾
}
System.out.println("2.MAX=" + run.maxMemory());// 返回最大可用内存空间
System.out.println("2.total=" + run.totalMemory());// 返回所有可用内存空间
System.out.println("2.free=" + run.freeMemory());// 返回空余内存空间
run.gc();// 用于手工释放内存。此处为释放垃圾空间
System.out.println("3.MAX=" + run.maxMemory());
System.out.println("3.total=" + run.totalMemory());
System.out.println("3.free=" + run.freeMemory());
long end = System.currentTimeMillis();// 取得结束时间
System.out.println("所用时间:" + (end - start));
}
}
标签:string time() 手工 ++ start memory for dex row
原文地址:https://www.cnblogs.com/Lovemeifyoudare/p/10403707.html