I have a javafx desktop application which after some time of usage accumulates a lot of objects in dirtynodes[] in one of the Scenes. Eclipse's tool MAT recognised this as a suspicious situation and possible leak. It is using 170 MB of memory which in my case is 30%. There are periodical updates of the nodes in that scene. Is there something I can do about this? Do those dirtynodes get cleaned? I am using java 8 u 51.
A small Java application might have a memory leak, but it will not matter if the JVM has enough memory to run your program. However, if your Java application runs constantly, then memory leaks will be a problem. This is because a continuously running program will eventually run out of memory resources.
In general, a Java memory leak happens when an application unintentionally (due to logical errors in code) holds on to object references that are no longer required. These unintentional object references prevent the built-in Java garbage collection mechanism from freeing up the memory consumed by these objects.
Dirty nodes are nodes in a scene which have been invalidated. They are processed once per frame so if JavaFX Application Thread (UI thread) is busy then the synchronization of dirty nodes cannot happen.
We had an issue in a screen with listview where every cell of the listview contained many rectangles and texts. The whole listview contained a few hundreds of nodes.
Cells in listview are not supposed to be reused but to be created every time the listview is repainted. When the listview had many lines and an user was holding scrollbar and moving it for a minute then synchronization of dirty nodes could not happen and we got out of memory exception because there were hundreds of tousends dirty nodes.
So my suggestion is to check if you are not blocking JavaFX Application Thread while adding the nodes to it.
Good practice is to create nodes in background thread and add it scene in UI thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With