Jump to content
co-

Memory Leak in Zomboid Game Engine

Recommended Posts

When I start a game or load a saved game multiple times, without quitting to desktop, quitting the current game takes more and more time to perform each time, until the game becomes completely unresponsive. The problem is present on vanilla even without any mod loaded. The computer I'm using has 32GB of RAM and it's far from being full when the problem happens. I usually start to feel the lag after approximately 10 games loaded or started, and the freeze usually happen after I start or load a few more games.

 

The error I get in console.txt is:

Exception thrown java.lang.OutOfMemoryError: Java heap space at HeapByteBuffer.<init>

Here's the stack trace when this is happening:

LOG  : General     , 1637028655102> EXITDEBUG: Core.quit 1
LOG  : General     , 1637028655103> EXITDEBUG: Core.quit 2
LOG  : General     , 1637028655103> EXITDEBUG: onMenuItemMouseDownMainMenu 3
LOG  : General     , 1637028655103> EXITDEBUG: IngameState.updateInternal 1
LOG  : General     , 1637028655103> EXITDEBUG: IngameState.updateInternal 2
LOG  : General     , 1637028655305> reanimate: saved 0 zombies
LOG  : General     , 1637028655311> Saving GlobalModData
ERROR: General     , 1637028658210> ExceptionLogger.logException> Exception thrown java.lang.OutOfMemoryError: Java heap space at HeapByteBuffer.<init>.
ERROR: General     , 1637028658211> DebugLogStream.printException> Stack trace:
java.lang.OutOfMemoryError: Java heap space
    at java.base/java.nio.HeapByteBuffer.<init>(Unknown Source)
    at java.base/java.nio.ByteBuffer.allocate(Unknown Source)
    at zombie.world.moddata.GlobalModData.save(GlobalModData.java:252)
    at zombie.GameWindow.save(GameWindow.java:1281)
    at zombie.gameStates.IngameState.updateInternal(IngameState.java:1420)
    at zombie.gameStates.IngameState.update(IngameState.java:1356)
    at zombie.gameStates.GameStateMachine.update(GameStateMachine.java:101)
    at zombie.GameWindow.logic(GameWindow.java:285)
    at zombie.GameWindow$$Lambda$202/0x0000000800cfcc90.run(Unknown Source)
    at zombie.core.profiling.AbstractPerformanceProfileProbe.invokeAndMeasure(AbstractPerformanceProfileProbe.java:71)
    at zombie.GameWindow.frameStep(GameWindow.java:726)
    at zombie.GameWindow.run_ez(GameWindow.java:642)
    at zombie.GameWindow.mainThread(GameWindow.java:471)
    at zombie.GameWindow$$Lambda$77/0x0000000800ac5818.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)
LOG  : General     , 1637028658211> EXITDEBUG: IngameState.updateInternal 3
LOG  : General     , 1637028658213> removing all player data
LOG  : General     , 1637028658213> - player: 0
LOG  : General     , 1637028658213> removing player inventory
LOG  : General     , 1637028658214> removing buttonprompts
LOG  : General     , 1637028658214> removing loot inventory

 

console.txt.zip

Share this post


Link to post
Share on other sites

In your console log I do see several game mods being loaded in the game. I would recommend you go to the Zomboid folder and delete the "Mods" folder to make sure none load. Then try replicating the issue. If it still happens, share the "logs.zip" file found in the Zomboid folder.

Share this post


Link to post
Share on other sites

Sure I will. That said, when I first started playing the game, even before I was aware I could download or make mods, I still had the same issue. So it's definitely not related to the mod you see in the log. Furthermore, after I posted this bug report, other people confirmed to me they had the same issue. Also, even assuming a bad mod allocating too many objects, the game engine should still free the memory when you quit the current game and start a new one .

Edited by co-

Share this post


Link to post
Share on other sites

21 minutes ago, co- said:

Sure I will. That said, when I first started playing the game, even before I was aware I could download or make mods, I still had the same issue. So it's definitely not related to the mod you see in the log. Furthermore, after I posted this bug report, other people confirmed to me they had the same issue. Also, even assuming a bad mod allocating too many objects, the game engine should still free the memory when you quit the current game and start a new one .


It’s far, far more likely that the mod is doing something inappropriate in its for() loop when it gets the contents of a square. It’s filling globalmoddata with something  and probably doing it every time a tile is loaded. 

 

Issues with the game can sound similar at first blush but not be related at all. For example, people might just remember that cars seemed to chug on long, zombie free drives, which is very similar on the surface. That was fixed some months ago, but they might remember and equate the two. Without reports from affected individuals, we simply can’t know.

Share this post


Link to post
Share on other sites

32 minutes ago, EnigmaGrey said:


It’s far, far more likely that the mod is doing something inappropriate in its for() loop when it gets the contents of a square. It’s filling globalmoddata with something  and probably doing it every time a tile is loaded. 

 

Issues with the game can sound similar at first blush but not be related at all. For example, people might just remember that cars seemed to chug on long, zombie free drives, which is very similar on the surface. That was fixed some months ago, but they might remember and equate the two.

It is definitely not the case, the mod you see are mod I made myself, they don't put allocated objects in GlobalModData or do anything with ModData in general, even less in a for loop. As mentioned earlier, I had the same bug even before I knew the existence of mods (I started to play Zomboid around august of this year). And this console log is from yesterday. The bug also happens when I only start new games each time instead of loading saved games. You can find a zip of my mod folder attached to this post. One (zReload) is an empty mod with no code in there, I just use it to force reload the Lua from mod screen. The other, OffTheWindow, is a mod I started yesterday to allow players to throw zombie corpses out of windows. It's just using the event OnFillWorldObjectContextMenu to add a context menu entry when you click a window.

mods.zip

Edited by co-

Share this post


Link to post
Share on other sites

Oh, and the bug happens only when I quit current game, or start a new game, or load a saved game. It's never happened while I was playing. And when I said the game is freezing, it's a real freeze like I have to force kill the game to be able to use it again.

Edited by co-

Share this post


Link to post
Share on other sites

I've noticed the slow down as well when testing my mods. After enough enable/disable cycles and game load/unloads there will be a noticeable increase in time to load and unload game files

Share this post


Link to post
Share on other sites

You're right, Co. Nothing to do with your mod!

It looks like the game is caching about 50 or so MB of animation or model data each time a new game is created. So after about 15 new games, the game crashes with an OOM. The exception with the mod and Lua was just a coincidence.

 

Good find. :)

Share this post


Link to post
Share on other sites

I think it's similar bug: (game crashes after many new games)

 

LOG  : General     , 1637246485730> EXITDEBUG: IngameState.exit 6
LOG  : General     , 1637246486403> EXITDEBUG: IngameState.exit 7
ERROR: General     , 1637246487714> GameWindow.uncaughtException> Unhandled java.lang.OutOfMemoryError thrown by thread MainThread.
ERROR: General     , 1637246487715> ExceptionLogger.logException> Exception thrown java.lang.OutOfMemoryError: Java heap space at TIntObjectHashMap.values line:352. Message: Unhandled java.lang.OutOfMemoryError thrown by thread MainThread.
ERROR: General     , 1637246487715> DebugLogStream.printException> Stack trace:
java.lang.OutOfMemoryError: Java heap space
    at gnu.trove.map.hash.TIntObjectHashMap.values(TIntObjectHashMap.java:352)
    at zombie.iso.sprite.IsoSpriteManager.Dispose(IsoSpriteManager.java:41)
    at zombie.iso.IsoWorld.KillCell(IsoWorld.java:2837)
    at zombie.gameStates.IngameState.exit(IngameState.java:877)
    at zombie.gameStates.GameStateMachine.update(GameStateMachine.java:105)
    at zombie.GameWindow.logic(GameWindow.java:285)
    at zombie.GameWindow$$Lambda$208/0x0000000800d16578.run(Unknown Source)
    at zombie.core.profiling.AbstractPerformanceProfileProbe.invokeAndMeasure(AbstractPerformanceProfileProbe.java:71)
    at zombie.GameWindow.frameStep(GameWindow.java:726)
    at zombie.GameWindow.run_ez(GameWindow.java:642)
    at zombie.GameWindow.mainThread(GameWindow.java:471)
    at zombie.GameWindow$$Lambda$82/0x0000000800ae6118.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)
LOG  : General     , 1637246487716> GameThread exited.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...