I am making a video game on javafx 1.3. In the game I have the concept of rounds. In my test round 200 enemy units are created and you blow them up. As each enemy unit dies it calls a "delete this from (parent as Group).content". The round object is a group and it has-a Group called enenyUnits, this is where the enemy units are stored.... in its content.
So aside from the enemy units themselves removing themselves from their parent Group, the round itself deletes the enemyUnits.content. Bottom line I cannot find any references to the individual enemy units. The factory that makes the enemy units just returns their instantiation... does not create a variable for them.
How do i free up the memory from these enemy units? Is removing them from the sequence they were in enough or does that sequence still some how keep a reference to them alive?
I also have test round with 6 enemy units and the memory leak is a lot less in those rounds. So I do suspect that it is the enemy units that is causing the leak. The bullets that kill the enemy units are reused, only 5 of them are instantiated.
java.lang.System.gc() might be be helpful for clearing the garbage manually.
There are some things you must consider before making game on javafx 1.3 like:
Initially loading the images and save them in def instead of 'var'. The game object must be light enough but must be cool. Use the effect, strokes only when essential. To preserve your memory and fast execution of object the cache is helpful property. Most fast animation,dragging time usually don't need any effects on object.
Thanks for the good tips. I'll look into all of them. Never heard of the cache property in javafx.
I already do the loading of images at the beginning, albeit they are vars not def's (going to change that). I'm going to have a loading screen so the player can see that things are loading. I also keep effects down to a minimum, they hardly get used.
The System.gc call does not seem to lower the memory. My tests show the same memory usage after calling it at the end of each round. Any ideas? I did not want to cache the enemy units, as there are going to be many of them. A simple question is this, if an object is added to a javafx sequence and the object is removed from that sequence using "delete", is a reference kept for that object?
Once you delete any object from the Sequence then the object becomes garbaged. And all the job comes to the Garbage Collector who clears it on time to time. But if you want those garbage to be cleared manually then System.gc() is there for.