This discussion is archived
6 Replies Latest reply: Dec 22, 2011 7:56 PM by jmart RSS

freeing up memory - or - memory leak issue

jmart Explorer
Currently Being Moderated
Hello,

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.

thanks
jose
  • 1. Re: freeing up memory - or - memory leak issue
    Narayan Pro
    Currently Being Moderated
    Hello jmart,

    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.
    Narayan
  • 2. Re: freeing up memory - or - memory leak issue
    DarrylBurke Guru Moderator
    Currently Being Moderated
    Do you end up with a <tt>OutOfMemoryError</tt>?

    db
  • 3. Re: freeing up memory - or - memory leak issue
    jmart Explorer
    Currently Being Moderated
    I have not ended up with that error yet. I am using Windows Task Manager to see how much mem is being used up. I notice the memory going up during each test round and never coming back down.

    I do a System.gc after each round and the mem still keeps going up.

    thanks!
    jose
  • 4. Re: freeing up memory - or - memory leak issue
    jmart Explorer
    Currently Being Moderated
    Narayan,

    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?


    thanks
    jose
  • 5. Re: freeing up memory - or - memory leak issue
    Narayan Pro
    Currently Being Moderated
    Hello jmart,

    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.

    Thanks.
    Narayan
  • 6. Re: freeing up memory - or - memory leak issue
    jmart Explorer
    Currently Being Moderated
    Hey I was able to get good GC performance and keep memory low by using the following JVM argument -J-XX:+UseConcMarkSweepGC

    thanks
    jose

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points