Dynamic Surroundings

Dynamic Surroundings

51M Downloads

Critical Memory Leak - Bypasses JVM memory limits and causes system instability/OS crashes

Gamebuster19901 opened this issue ยท 6 comments

commented

Mod Version:
DynamicSurroundings-1.12.2-3.4.7.2

Forge Version:
14.23.3.2655 for Minecraft 1.12.2

Link to crash log (if applicable):
Game log (Critical memory loss occurs at 12:51:53):
https://pastebin.com/tYHf9H4b

Windows Events:
https://docs.google.com/spreadsheets/d/1-1eSFm-LVHV6gVtrVrQouyIPbQy13gbo1uxELj--ty4/edit?usp=sharing

Description:
I was working on my mod yesterday and left the game open a few hours while I went to work. I was in survival mode and was killed. When I came back from work, Windows displayed a warning for me to close javaw.exe to prevent memory loss. Most of my other running programs (including Minecraft, Eclipse, and Paint.net) had either crashed or hung, so I lost some minor progress on those. I only had 1GB of RAM allocated to Minecraft at the time. I only had Forge, DynamicSurroundings, and InventoryDecrapifier (my mod) running at the time.

The leak occurs when sounds play or attempt to play while the player has died and hasn't respawned. The memory does not clear after the player has respawned, and only clears when the java process is terminated. Again, the leak only occurs with DynamicSurroundings installed, and does not occur with just Forge and InventoryDecrapifier or plain Forge. This leak will NOT throw OutOfMemoryError, it will use all available system memory.

An faster way to see the leak is to:

  1. Open the task manager and view memory usage
  2. Launch Minecraft 1GB of RAM allocated and with the DynamicSurroundings mod
  3. Load a world and turn maxEntityCramming and doWeatherCycle off
  4. dig a hole and spawn 40 or so chickens
  5. toggledownfall
  6. Jump in the hole and set up a command block to /kill you every tick
  7. Respawn every few seconds for a few minutes
  8. Watch memory usage increase well beyond the JVM's limits, notice a lot of sounds stop playing also

I have not been able to figure exactly why or where it happens, as inspecting the heapspace with jvisualvm shows that Minecaft's memory usage within the JVM is lower than the allocated amount, but the task manager shows the javaw.exe process is consuming ludicrous amounts of memory. I also noticed a LOT (over 550,000) instances of HashMap$Node. HashMap$Node had more instances than any other object.

commented

This is interesting. I will take a look. The handling of player death in Minecraft can be kinda weird.

commented

Think I found the issue. DS appears to be beating it's head against the sound manager trying to play biome sounds when the player is dead. Should be a straight forward fix.

commented

IResource does not have a close method. However, the stream that I obtain is auto closed by the "try" on line 88.

As for the SoundInputStream that is closed down in the underlying sound library that Minecraft uses (PaulsCode). Don't have the specific location at the moment.

commented

I have a couple questions:

Is the InputStream on line 88 of org.blockartistry.Presets.proxy.ProxyClient ever closed?
Is the SoundInputStream on line 57 of org.blockartistry.lib.sound ever closed?

I can't seem to find where these are closed (but you know more about the sound engine than I do). If they aren't closed, then they could be leaking memory.

commented

Pushed v3.4.9.13 to CurseForge. Let me know if this does the trick for you.

commented

Looks good.