当我想退出整个程序时我是用dispose好还是system.exit(0)好

解决方案 »

  1.   

    system.exit(0):正常情况下退出
    system.exit(-1):发生错误退出
    还有抛出异常的方式:throw new Throwable();
    dispose?不知道你说的是什么
      

  2.   

    从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). 
      

  3.   

    java是门简单的学问,只要看JAVADOC就搞定了
      

  4.   

    如果你遇到了必须退出的情况,可以用exit()否则你还是从方法返回比较好。
      

  5.   

    dispose()释放资源,关闭窗口,显然不行!
    System.exit(0)才是结束程序!
      

  6.   

    到底哪个System.exit(0)是终止jvm
    dispose()是释放资源。。
    那么System.exit(0)是否也释放资源???
      

  7.   

    system.exit(0)比较好吧,如果是退出的话
      

  8.   

    还是让所有非守护线程自然执行结束然后程序退出好,System.exit(0); 更好的比喻是程序自杀。
      

  9.   

    从内存的利用的角度来说dispose比较好
    System.exit(0)只是结束程序没有释放内存,等着垃圾处理程序销毁
    dispose就连内存也一起销毁
      

  10.   


    可是,java的垃圾回收机制本来就是做这个事的啊,java既然为我们提供了这个方便,为什么还要自己去收拾这些东西呢?这样岂不是又陷入了C的境地?
      

  11.   

    dispose 方法多是在回收不在 JVM 管辖范围内的资源,或手动提前释放掉具有较大的系统开销的对象时使用(等GC回收有可能损失性能)。dispose 跟程序的退出没什么关系,因为你的程序退出后 JVM 会释放掉一切它所占用的资源(一些本地资源除外但基本很少使用),而不像 C++ 等可以直接操作内存的程序可能造成真正意义上的内存泄露。