system.exit(0):正常情况下退出 system.exit(-1):发生错误退出 还有抛出异常的方式:throw new Throwable(); dispose?不知道你说的是什么
从dispose在javadoc中的解释可以完美解释楼主的问题, 结论:如果是为了退出程序,显然是不能单纯通过调用dispose来实现。 disposepublic void dispose() Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children. That is, the resources for these Components will be destroyed, any memory they consume will be returned to the OS, and they will be ed as undisplayable. The Window and its subcomponents can be made displayable again by rebuilding the native resources with a subsequent call to pack or show. The states of the recreated Window and its subcomponents will be identical to the states of these objects at the point where the Window was disposed (not accounting for additional modifications between those actions).
system.exit(-1):发生错误退出
还有抛出异常的方式:throw new Throwable();
dispose?不知道你说的是什么
结论:如果是为了退出程序,显然是不能单纯通过调用dispose来实现。
disposepublic void dispose() Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children. That is, the resources for these Components will be destroyed, any memory they consume will be returned to the OS, and they will be ed as undisplayable. The Window and its subcomponents can be made displayable again by rebuilding the native resources with a subsequent call to pack or show. The states of the recreated Window and its subcomponents will be identical to the states of these objects at the point where the Window was disposed (not accounting for additional modifications between those actions).
System.exit(0)才是结束程序!
dispose()是释放资源。。
那么System.exit(0)是否也释放资源???
System.exit(0)只是结束程序没有释放内存,等着垃圾处理程序销毁
dispose就连内存也一起销毁
可是,java的垃圾回收机制本来就是做这个事的啊,java既然为我们提供了这个方便,为什么还要自己去收拾这些东西呢?这样岂不是又陷入了C的境地?