处理JFrame会导致内存泄漏吗? [英] Does disposing a JFrame cause memory leakage?

查看:144
本文介绍了处理JFrame会导致内存泄漏吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写如下测试程序:

I am writing a test program as follows:


  1. 当用户点击按钮A时,它会打开50个JFrame。

  2. 当用户点击按钮B时,它会通过点击按钮A来处理所有显示的JFrame。

我发现单击按钮B后内存没有减少。我在Windows中使用任务管理器 ctrl + alt + del 确定了这一点,并检查java的内存使用情况。

I find that the memory does not decrease after clicking button B. I determined this using the Task Manager, ctrl+alt+del in Windows, and checking the memory usage of "java".

推荐答案

这是对的,没办法,不能解决(不仅仅是Java PL),

That's right, no way, not able to solve that (not only in Java PL),

1)真的不会创建大量顶级容器,因为它们从未最终确定,并且直到当前的JVM实例退出,并且这些对象从未被GC只用于 Grapfics2D

1) really don't create lots of Top-Level Containers on Runtime/Fly, because they are never finalized, and until current JVM instance exits, and these Object never been GC'ed only their Grapfics2D

2) myContainer#dispose() on Runtime is当前JVM实例与 myContainer #setVisible(false)相同,与JVM可用和使用的内存连接

2) myContainer#dispose() on Runtime is same for current JVM instance as myContainer#setVisible(false) in connections with JVM available and used Memory

3)只创建少量顶级容器(最多同时显示),重新使用,但放在那里< a href =https://stackoverflow.com/questions/6309407/remove-top-level-container-on-runtime> JPanel 为1.st JComponent 并调用 myPanel #removeAll(),否则你将删除 RootPane 并且从您的Container只保留Borders :-)将是半透明的

3) create only few Top-Level Containers (maximum simultaneously displayed ), re-use that, but put there JPanel as 1.st JComponent and call myPanel#removeAll(), otherwise you'll remove RootPane and from your Container stays only Borders :-) would be translucent

4)partialy是可能的通过调用GC减少JVM使用的内存,但只是从 Graphics2D 中重新调整数量垃圾不能立即生效,

4) partialy is possible to reduce JVM used Memory by call GC, but just returs amount from Graphics2D and Garbage doesn't works immediatelly,

5)更多此处有用的信息此处

5) more here usefull info here

这篇关于处理JFrame会导致内存泄漏吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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