In my game, I use a linked list (the concept, not the built in Java one), to add/remove entities. I fear however, that when an entity is removed from the linked list and it’s reference is set to null, that it is not completely being destroyed. I believe that Java sometimes keeps ties to my ‘deleted’ nodes long after I have tried to get rid of them.
What I know: Java sometimes gets rid of my nodes… eventually. I know that it sometimes takes the garbage collector a while to unallocate memory. I know that at least some nodes are eventually removed- otherwise the game would crash from memory overflow. (Since I’d keep making new nodes without removing old ones.)
What I don’t know: In my game, I sometimes get erratic behavior when nodes are deleted which leads me to believe that sometimes they arn’t deleted at all. I have no way of testing this however, which is why I’m asking here if anyone has seen/done any testing on this.
Here’s a simple example of how I’m doing this:
http://www.funkapotamus.org/linkedlist/Node.java
http://www.funkapotamus.org/linkedlist/Test.java
Oh, and if anyone knows a better method for dynamically spawning and killing entities (particles, monsters, bullets, etc.) in a high fps game, I’m open to suggestions.