JavaFX 8隐藏阶段时发生内存泄漏

我有一个JavaFX应用程序,当按下Xbutton时最小化托盘。 我一直在通过VisualVM监视应用程序的内存趋势。

怪异的部分是,当应用程序打开或最小化到任务栏时,内存总是回到使用的初始内存。 但是,当它最小化到托盘( stage.hide()stage.hide() )时,内存得到GCed,但处于上升趋势(泄漏)。

在VisualVM中,旧版空间不断增加,一旦达到最大值,应用程序将无响应,CPU高达80%。

我注意到, 如果我通过双击托盘图标等stage.show()应用程序,GC将清除一切恢复正常 。 但是,如果长时间离开,那么根本就不会GC老一辈。

堆转储显示javafx.scene.Scene#7javafx.scene.Node[]#2具有最多的保留空间。 如果舞台没有隐藏,两者都不会出现。 在引用下,它显示了this[] -> dirtyNodes()

 this - value: javafx.scene.Node[] #2 <- dirtyNodes - class: javafx.scene.Scene, value: javafx.scene.Node[] #2 <- value - class: javafx.scene.Node$ReadOnlyObjectWrapperManualFire, value: javafx.scene.Scene #7 

是什么原因造成的,我该如何解决?

我从来没有find答案。 相反,我会隐藏节点上的节点并恢复它的视图。 对于密集的dynamic节点/多个节点,我创build了一个哈希映射将它们存储在内存中。

这在javafx8中已经成为一种习惯,用于处理所有graphics,并重新指定隐藏和查看哈希映射。 现代桌面上额外的内存和CPU使用率可以忽略不计。 使用这种方法,我已经有0个CPU使用的应用程序和低内存应用程序(约100米)运行时隐藏在WIN8 / 10上。

Java的function与Weak Reference相似: https : //docs.oracle.com/javase/7/docs/api/java/lang/ref/WeakReference.html

软参考: https : //docs.oracle.com/javase/7/docs/api/java/lang/ref/SoftReference.html

这些允许你专门针对虚拟机 – >>什么垃圾收集。

另外还有并发API http://winterbe.com/posts/2015/04/07/java8-concurrency-tutorial-thread-executor-examples/

那使用执行程序服务和线程池。

和限制内存的应用程序在Java软件应该调用

System.gc() // garbage collector

不pipe其自动调用如何

您可以使用Runtime类为项目计划负载均衡器https://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html

 public Process exec(String command) throws IOException //-------------------------------------------------------- Executes the specified string command in a separate process. public void gc() //---------------------------------------------------------- Runs the garbage collector. Calling this method suggests that the Java virtual machine expends effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the method call, the virtual machine has made its best effort to recycle all discarded objects This is a convenience method. An invocation of the form exec(command) behaves in exactly the same way as the invocation exec(command, null, null). 

线程一直是内存密集型应用程序的一个问题,在JavaFX中,场景中的每个组件都紧密地绑定到一个场景,但是就实现而言,似乎是松散的。

如果需要长时间运行,则最好处理Native端(JNI)中的一些处理器密集型任务。 而且,CLEAN架构将会受益

https://www.google.co.in/webhp?sourceid=chrome-instant&rlz=1C1CHBF_enIN736IN736&ion=1&espv=2&ie=UTF-8#q=clean+code&; *