JDialog setVisible(false)vs dispose() [英] JDialog setVisible(false) vs dispose()

查看:126
本文介绍了JDialog setVisible(false)vs dispose()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在对话框中使用setVisible(false)并在以后重用它是否有意义,或者每次调用dispose()更安全并创建一个新的JDialog。
使用setVisible(false)内存泄漏怎么样?

Does it make sense to use setVisible(false) on a dialog and reuse it later or is safer to call dispose() every time and to make a new JDialog. What about memory leaks with setVisible(false)?

编辑:
我的问题不在于退出应用程序。有关将主框架作为父框架并在应用程序生命周期内打开和关闭的对话框的更多信息。例如。假设我的应用程序有大约10个对话框,每次打开它们时都会显示不同的数据。我应该重用实例并使用setVisible(),还是应该每次都创建一个新的Dialog,并在关闭时处理它们。

My Question isn't so much about quitting the application. More about Dialogs that have the main frame as parent and are opened and closed during the application life time. E.g. let's say my applications has about 10 dialogs that display different data every time I open them. Should I reuse the instances and use setVisible() or should I make a new Dialog every time and dispose() them on closing.

推荐答案

我建议使用 dispose() 释放资源并释放内存。如果要再次显示该对话框,只需调用 setVisible(true)

重要的是要注意,当Java虚拟机(VM)中的最后一个可显示窗口被丢弃时,VM可能会终止。请参阅 AWT线程问题了解更多信息。

It's important to note that 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.

这篇关于JDialog setVisible(false)vs dispose()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆