Exception in thread "StateCollectionThread" Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError

I m using bullet integration SiO2/extensions/bullet/src/main/java/com/simsilica/bullet at master · Simsilica/SiO2 · GitHub
for my sim-eth-es based game. Server part is separated from app. I`ve recently added 4 basic entities which wanders, performed some basic heuristics and so on… basically some of the actions player character does. I m using jdk 8. I really do not know what part of code, dependencies, run parameters, heap dump and so on to post all i know that used heap is rapidly rising and some time ‘server’ crashes. Following happens without any connections. just to reproduce the problem run the server with -Xmx150m. Running 43 mins and after 15 mins crashes. So maybe if there is nothing wrong in is such behaviour reasonable question will be: What is the reasonable memory resource i need to have for disposal.

Imgur

Imgur

collect underflow FPS:1
collect underflow FPS:2
collect underflow FPS:1
collect underflow FPS:3
collect underflow FPS:2java.lang.OutOfMemoryError: Java heap space

collect underflow FPS:1
collect underflow FPS:5
Exception in thread "RMI TCP Connection(idle)" Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: Java heap space
collect underflow FPS:4
collect underflow FPS:2
collect underflow FPS:2
Exception in thread "StateCollectionThread" java.lang.OutOfMemoryError: Java heap space
07:00:41.769 [GameLoopThread] ERROR com.simsilica.sim.GameSystemManager - Error updating systems
java.lang.OutOfMemoryError: Java heap space
Exception in thread "Selector@0.0.0.0/0.0.0.0:4271" java.lang.OutOfMemoryError: Java heap space: failed reallocation of scalar replaced objects
07:01:22.011 [GameLoopThread] ERROR com.simsilica.sim.GameSystemManager - Error updating systems
java.lang.OutOfMemoryError: Java heap space
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space
Exception in thread "RMI TCP Connection(idle)" Exception in thread "RMI TCP Connection(idle)" 
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "RMI TCP Connection(idle)"
java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: Java heap space
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space
Exception in thread "GameLoopThread" java.lang.OutOfMemoryError: Java heap space
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space
Exception in thread "RMI TCP Connection(idle)" Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: Java heap space
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space

This is definitely not normal behavior. The most likely issue is you have a collection in your code that’s growing (rapidly) over time, although it could also be a bug in another library you’re using. The RMI thread errors are probably from the monitoring tool - it uses RMI to communicate with the JVM. I can’t tell from the screenshots if you’re using Netbeans or VisualVM, but in either tool you should be able to get a heap snapshot that will show you the offending class, and if it’s your code that should almost give away the cause of the error.

Yeah, you are stacking up those ConcurrentLinkedQueues. Find the source.

One repeating offense with the pspeed’s entity system seems to be that people create those change listeners and forget to update them. They’ll just keep stacking up changes until you run out of memory.

Yeah, if ConcurrentLinkedQueue is building up lots of current references then the most likely cause is that you create EntitySets and never update/release them… or WatchedEntity and never update/release them.

(which indicates a design problem if you are doing that so often)

Thanks for the direction, at least now i know where to start looking for problem and i will update my findings or post code for codereview. I will try also using Eclipse Memory Analyzer Open Source Project | The Eclipse Foundation along with searching for the naughty AbstractGameSystem.

So without repeating upper comments the specific problem seems to be getEntities() without applyChanges or release in couple instances of same class… (really single case I m doing such things and not using EntityContainer ). How I m observing the problem visualvm->Sampler->Memory and looking for the count of “living” ConcurrentLinkedQueue-s in time. I will check for other places in code run it for couple days to see if this will occure. If I figure out some kind of integration test will be cool.