8 Replies Latest reply on Feb 6, 2012 7:17 AM by 895058

    How to dynamically remove children and free memory?

      Hi everybody,

      I am developing a visualization which uses a lot of rectangles (in the 10.000's), each having a width of 1px. I want to keep the 1px width of the Rectangles at any scale of the ui and at any zoom level on the data set. So, I am re-painting the whole scene of rectangles on ui-resize and user interacation. (Just scaling the components is not sufficient)

      Here is my problem: I noticed an enormous memory usage of my application, increasing on every re-paining of the data set. It quickly reaches around 1GB which is a problem on 32-Bit sytsems. I conclude that the old rectangles are not properly removed and garbage collected. What can I do about this issue?

      I currently create the rectangles and add them as children of a javafx.scene.layout.Pane class. At every update of the scene, I remove all children of the Pane (I have tried both: getChildren.clear() and getChildren.removeAll()) before adding a new set of Rectangles as children. The visual result is as expected but the increasing memory usage is inacceptable. What is wrong with this solution? Why is the memory usage constantly going up?