1.打开一个窗口,内存用了1M
2.关闭窗口,内存的使用不见下降;有时甚至上升?
3.连续打开关闭之后,内存冲到95,之后由Memory异常抛出?:窗口用dispose()不能释放程序占用的内存吗?(是不是Swing控件的问题)
:有什么工具可以检测的?
ps:我用的是eclipse

解决方案 »

  1.   

    内存管理应该是属于OS的工作,你的程序执行dispose()以后窗口的内存应该存在于gc的最后一个时代了,但是什么时候回收,java的gc会再下次检查堆的时候回收。这一点与c++不同,这种自动对java以及c#这些依赖gc机制的语言带来不小的问题。关于内存回收gc的问题,建议你去csdn的java社区,里面有sun的专业资深人员的音频讲解,我看过,听了以后肯定比我说的明白的多
      

  2.   

    应该表示dispose()的问题
    --------------------------------------------------------
    dispose
    public 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). Note: When the last displayable window within the Java virtual machine (VM) is disposed of, the VM may terminate. See AWT Threading Issues for more information.
      

  3.   

    到底是什么问题呢?
    是不是JVM的问题;程序间的相互引用能不能被GC回收?