Question..
Given: 11 rob =new ReallyBigObject();
12 //more code here
13 rbo =null;
14 /* insert code here */
which statement should be placed at line 14 to suggest that the virtual machine expend efforttoward recycling the memory used by the object rbo? A System.gc();
B Runtime.gc(); C System.freeMemory(); D Runtime.getRuntime().growHeap();
E Runtime.getRuntime().freeMemory();
Answer A
求解释呢
Given: 11 rob =new ReallyBigObject();
12 //more code here
13 rbo =null;
14 /* insert code here */
which statement should be placed at line 14 to suggest that the virtual machine expend efforttoward recycling the memory used by the object rbo? A System.gc();
B Runtime.gc(); C System.freeMemory(); D Runtime.getRuntime().growHeap();
E Runtime.getRuntime().freeMemory();
Answer A
求解释呢
public static void gc()运行垃圾回收器。
调用 gc 方法暗示着 Java 虚拟机做了一些努力来回收未用对象,以便能够快速地重用这些对象当前占用的内存。当控制权从方法调用中返回时,虚拟机已经尽最大努力从所有丢弃的对象中回收了空间。 调用 System.gc() 实际上等效于调用: Runtime.getRuntime().gc()