Search code examples
javaperformanceuser-interfacejavafxlag

JavaFX: Heavy laggs after a specific time


We're working on a little game with JavaFX for the GUI. The game is turn-based and after each turn we update our borderPane (.setCenter()) with the new board (this is an array which representes the tiles in the game). The tiles are drawn as JavaFX-Canvas objects.

We have the problem that every time after 155-160 turns the whole application begins to lag. CPU usage is increasing to 80% on my computer by one turn (e.g. turn 154: 1 % und turn 155: 80%). We also got an outOfMemoryError but not every time.

Additionally, we implemented some sysos for debugging and all the methods on our board array with the game logics are correctly and fastly iterated. The lag must be something in the JavaFX-Thread.

Can you help me?

Thanks a lot :)


Solution

  • The gc maybe isnt cleaning old objects. Did you try to use the daneobjects but not creating a new one every time?

    Greets