main.java
来自「<设计模式-Java语言中的应用> 的源码」· Java 代码 · 共 22 行
JAVA
22 行
public class Main {
private static BigString[] bsarray = new BigString[1000];
public static void main(String[] args) {
System.out.println("共享时:");
testAllocation(true);
System.out.println("不共享时:");
testAllocation(false);
}
public static void testAllocation(boolean shared) {
for (int i = 0; i < bsarray.length; i++) {
bsarray[i] = new BigString("1212123", shared);
}
showMemory();
}
public static void showMemory() {
Runtime.getRuntime().gc();
long used = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
System.out.println("内存使用量= " + used);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?