跟垃圾收集使用的算法等相关,这里一个例子: For an example of a garbage collector that would usually ignore the System.gc() suggestion completely, consider a copying collector. That kind of garbage collector doesn't collect until it fills up half of the heap. So if you heap doesn't happen to be half full when you call System.gc(), no objects will be reclaimed.
struts2 不就是整合了webwork嘛?
那肯定会出现错误,而且在一个大项目中需要清理的东西很多,可在哪清理,什么时候清理是一个大难题,很麻烦。
那为什么不交给系统自己清理呢?
这样,在JAVA中就可以调用finalize()这个方法清理,当然这个方法只是提醒JVM需要清理,它有可能被清理,但这只是JVM 的事情,你控制不了它。
public static void gc()运行垃圾回收器。
调用 gc 方法暗示着 Java 虚拟机做了一些努力来回收未用对象,以便能够快速地重用这些对象当前占用的内存。当控制权从方法调用中返回时,虚拟机已经尽最大努力从所有丢弃的对象中回收了空间。 调用 System.gc() 实际上等效于调用: Runtime.getRuntime().gc()
这个方法已经会“尽力”回收了。
个人观点 不代表权威 呵呵!!~~
For an example of a garbage collector that would usually ignore
the System.gc() suggestion completely, consider a copying
collector. That kind of garbage collector doesn't collect
until it fills up half of the heap. So if you heap doesn't
happen to be half full when you call System.gc(), no objects
will be reclaimed.