Skip to content

GameEventDispatcherStorage retains LevelChunks forever — memory leak when chunks unload (mixin.world.game_events.dispatch) #783

Open

Description

@loliking-01

Issue: [NeoForge] GameEventDispatcherStorage retains LevelChunks forever — memory leak when chunks unload (mixin.world.game_events.dispatch)

Reported against: lithium-neoforge 0.15.4+mc1.21.1 (official CaffeineMC build)


Environment

Component Version
Minecraft 1.21.1
NeoForge 21.1.250
Lithium 0.15.4+mc1.21.1
Java 21 (dedicated server, Windows 11 x64)
Heap 16 GB (-Xmx16G)
Worldgen Big Globe (builderb0y) world generator
Workload amplifier Chunky chunk pre-generator (used to make the leak visible quickly — plain exploration reproduces it, just much slower)

Summary

When mixin.world.game_events.dispatch is enabled, every LevelChunk that has ever been loaded is held by a strong reference inside lithium's GameEventDispatcherStorage and is never released on chunk unload. The server leaks roughly the full loaded-chunk population permanently; after a pre-generation run of ~41k chunks the heap was 88.4% retained LevelChunk instances and full GCs could not reclaim anything.

Symptom

  • MAT Leak Suspects on a 12.8 GB heap dump: 41,359 instances of LevelChunk retaining 12,143,806,488 bytes (88.38%).
  • Pausing chunk generation does not help: chunk retention count stayed frozen at 17,668 for 8+ minutes with zero players online and nothing loading new terrain.
  • Full GCs (System.gc() via jcmd) reclaim only a few thousand instances of temporary noise; the bulk never leaves the Long2ReferenceOpenHashMap described below.

Root cause (evidence)

MAT Merge Shortest Paths to GC Roots on a 10,000-sample of retained LevelChunks shows 9,975 instances reachable through a single path:

Server thread
 └─ MinecraftServer (DedicatedServer)
     └─ ServerLevel[8][0]                        (overworld)
         └─ LithiumData$Data                     (net.caffeinemc.mods.lithium.common.world.LithiumData)
             └─ GameEventDispatcherStorage
                 └─ Long2ReferenceOpenHashMap    (table: Object[32769], grown)
                     └─ per-section Int2ObjectOpenHashMap listeners
                         └─ LevelChunk  ← held forever

Relevant mixins (from the 0.15.4 jar / Force-disable log):

  • world.game_events.dispatch.GameEventDispatcherMixin
  • world.game_events.dispatch.LevelChunkMixin

The storage is keyed per section and appears to be populated on chunk load, but nothing removes the entries when a chunk unloads on NeoForge — the section → listener map keeps a strong reference chain to the chunk itself. Suspected NeoForge port gap: no chunk-unload hook wired into this storage.

Reproduction

  1. Dedicated server, NeoForge 21.1.250 + lithium 0.15.4 (default config).
  2. Load terrain (teleport around or run chunky start), then unload it (teleport away / chunky pause).
  3. Count live chunks: jcmd <pid> GC.class_histogram | grep net.minecraft.world.level.chunk.LevelChunk.
  4. Expected: instance count drops back toward spawn-radius levels after unload + GC. Observed: count is pinned at the high-water mark indefinitely.

Control experiment (proves the mixin is the culprit)

Added to config/lithium.properties:

mixin.world.game_events.dispatch=false

Restarted, re-ran the same Chunky workload at full speed (~27 GB/s allocation rate observed):

  • Startup log confirms: world.game_events.dispatch.GameEventDispatcherMixin and world.game_events.dispatch.LevelChunkMixin were Force-disabled.
  • Chunk retention now oscillates normally (464 → 440 → 914 across samples) instead of pinning at the high-water mark.
  • Heap stays stable around 1.6 GB where it previously ballooned past 12 GB and wedged.

Expected fix

GameEventDispatcherStorage (and/or LevelChunkMixin) must drop section entries on chunk unload, matching Fabric behavior — or the NeoForge port should be audited for a missing unload hook.

Workaround (until fixed)

# config/lithium.properties
mixin.world.game_events.dispatch=false

Cost: game-event listening dispatch loses the lithium optimization (vibration sensors / sculk mechanics run on vanilla path). Acceptable for affected servers.


Appendix: Full Environment

Machine

Item Value
Hardware ASUS TUF Gaming F15 (FX507ZR) laptop
CPU 12th Gen Intel Core i7-12700H (14C/20T, 6P+8E)
RAM 32 GB (31.6 GB usable)
OS Windows 11 (build 26200), x64
Java Eclipse Temurin 21.0.12.1+1 LTS, HotSpot 64-Bit Server VM

JVM arguments (user_jvm_args.txt)

-Xms14G
-Xmx14G
-XX:+UseG1GC
-XX:+ParallelRefProcEnabled
-XX:MaxGCPauseMillis=200
-XX:+UnlockExperimentalVMOptions
-XX:+DisableExplicitGC
-XX:+AlwaysPreTouch
-XX:G1NewSizePercent=40
-XX:G1MaxNewSizePercent=50
-XX:G1HeapRegionSize=16M
-XX:G1ReservePercent=15
-XX:G1HeapWastePercent=5
-XX:G1MixedGCCountTarget=4
-XX:InitiatingHeapOccupancyPercent=20
-XX:G1MixedGCLiveThresholdPercent=90
-XX:G1RSetUpdatingPauseTimePercent=5
-XX:SurvivorRatio=32
-XX:MaxTenuringThreshold=1
-XX:+PerfDisableSharedMem
-Xlog:gc*:file=logs/gc.log:time,uptime,level,tags:filecount=5,filesize=10M

Note: the leak reproduces with default -Xmx16G/plain G1 flags too — the args above were only tuned afterwards.

Relevant server.properties values

level-type=bigglobe:bigglobe
view-distance=10
simulation-distance=10
max-tick-time=0
sync-chunk-writes=true
spawn-protection=0
difficulty=hard

Lithium config

config/lithium.properties was default (empty) at the time of the leak. After diagnosis, the single line below was added (this is the workaround, not the repro state):

mixin.world.game_events.dispatch=false

Full mod list (mods/ directory, 195 jars)

Big Globe (worldgen) and Chunky (pre-generator) are the workload amplifiers. Sinytra Connector + Forgified Fabric API are present.

1.21.1-maid_storage_manager-1.15.6.jar
AeroEngine-1.3.0.jar
Aquaculture-1.21.1-2.7.21.jar
Big Globe-5.3.2-MC1.21.1.jar
BrewinAndChewin-neoforge-4.5.0+1.21.1.jar
CreateDragonsPlus-1.11.9.jar
CreateEntityControl-0.6.16.10-6.0.x-neoforge-1.21.1.jar
Create_Bugfix_Schematic_Patch-1.1.4.jar
DnDesires-1.21.1-2.3a-BETA.jar
Ecliptic-Seasons-MultiMod-Patch-1.21.1-neoforge-0.32.1.jar
EclipticSeasons-1.21.1-neoforge-0.15.0-rc-3-1.jar
EclipticSeasons-Bundles-0.18.0.2.jar
ExtraLib-3.1.1-1.21.1-NeoForge.jar
ExtraQuests-1.7.0-1.21.1-NeoForge.jar
FantasyCraft-1.0.0-NeoForge-1.21.1.jar
FarmersDelight-1.21.1-1.3.4.jar
FastWorkbench-1.21.1-9.1.3.jar
IllagerInvasion-v21.1.6-1.21.1-NeoForge.jar
Jade-1.21.1-NeoForge-15.10.6.jar
MaidUseHandCrank_1.6.2-neoforge_21.1.219-1.21.1.jar
NoChatReports-NEOFORGE-1.21.1-v2.9.1.jar
Not Enough Recipe Book-NEOFORGE-0.4.3+1.21.jar
OctoLib-NEOFORGE-0.6.2+1.21.jar
Patchouli-1.21.1-93-NEOFORGE.jar
Placebo-1.21.1-9.9.2.jar
PuzzlesLib-v21.1.60-mc1.21.1-NeoForge.jar
RamadanDelight-1.21.1-1.7.jar
VeggiesDelight-1.21.1-1.9.3.jar
Vertigo-1.2.4-MC1.21.1.jar
XaeroPlus-2.36.3+neoforge-1.21.1-WM1.46.0-MM26.5.0.jar
ZstdNet-1.21.1-neoforge-server-client-0.1.0.jar
[2] Almanac-1.21.1-2-neoforge-1.5.2.jar
[2] Chunky-NeoForge-1.4.23.jar
[2] FastFurnace-1.21.1-9.0.1.jar
[2] OpenLoader-neoforge-1.21.1-21.1.5.jar
[2] alternate_current-mc1.21-1.9.0.jar
[2] fastleafdecay-35.jar
[2] lakefeaturefix-neoforge-1.21.1-21.0.0.jar
[2] leaky-1.21-3.4.jar
[2] letmedespawn-1.21.x-neoforge-1.5.0.jar
[2] lmft-1.1.1+1.21.9-neoforge.jar
[2] sable_fix_mod-1.1.0.jar
[2] servercore-neoforge-1.5.19+1.21.1.jar
[2] spark-1.10.124-neoforge.jar
aerocopycats-1.1.1.jar
aeronauticscompat-1.1.3.jar
aeroworks-1.5.0.jar
alltheleaks-1.1.13+1.21.1-neoforge.jar
animal_pen-neoforge-1.21-2.4.3.jar
appleskin-neoforge-mc1.21-3.0.9.jar
appliedenergistics2-19.2.17.jar
aquaculturedelight-1.2.0-neoforge-1.21.1.jar
architectury-13.0.11-neoforge.jar
atomchat-NeoForge-1.21.1-0.2.11.jar
attributefix-neoforge-1.21.1-21.1.3.jar
attributefixsync-0.0.2.jar
baguettelib-1.21.1-NeoForge-2.0.7.jar
bakeries-1.21.1-NeoForge-1.0.4.jar
balancedflight-1.21.1_v2.5.0.jar
balm-neoforge-1.21.1-21.0.65.jar
barbequesdelight-1.3.0.jar
betterdays-1.21.1-3.3.6.3-NEOFORGE.jar
bookshelf-neoforge-1.21.1-21.1.81.jar
bountifulharvest-1.0.0.jar
butchercraft-2.6.5.jar
caelus-neoforge-7.0.1+1.21.1.jar
cc-tweaked-1.21.1-forge-1.120.2.jar
cloth-config-15.0.140-neoforge.jar
cointoshop-neoforge-1.21.1-1.1.1.jar
concoction-1.6.2-neoforge (1.21-1.21.1).jar
connector-2.0.0-beta.17+1.21.1-full.jar
cookingforblockheads-neoforge-1.21.1-21.1.24.jar
copycats-3.0.9+mc.1.21.1-neoforge.jar
corn_delight-1.2.10-1.21.1.jar
corpse-neoforge-1.21.1-1.1.13.jar
corpsecurioscompat-1.21.1-NeoForge-4.0.1.jar
create-1.21.1-6.0.10.jar
create-aeronautics-bundled-1.21.1-1.3.2.jar
create-enchantment-industry-2.5.4.jar
create-integrated-farming-1.4.3.jar
create-routes-mc1.21.1-0.2.0.jar
create-schematic-compute-1.2.5.1.jar
create-stuff-additions1.21.1_v2.1.4b.jar
create_aeronautics_toolgun-0.3.6.jar
create_bitterballen+1.21.1-1.0.4.jar
create_bugfix_clipboard_patch-1.0.0.jar
create_connected-1.3.3-mc1.21.1.jar
create_deepfried-forge-1.21.1-0.1.3C.jar
create_flight_control-neoforge-0.7.5.jar
create_power_loader-2.0.5-mc1.21.1.jar
createaddition-1.7.1.jar
createcafe-1.4.3.jar
createdieselgenerators-1.21.1-1.3.15.jar
createfactorycontroller-1.2.1-neoforge-1.21.1.jar
createnuclear-1.3.2-beta.3-neoforge.jar
createoreexcavation-1.21-1.6.8.jar
cuisinedelight-1.2.10.jar
cupboard-1.21.1-4.2.jar
curios-neoforge-9.5.1+1.21.1.jar
dashpanels-2.1+neoforge1.21.1.jar
deployer-0.1.3.jar
dimdungeons-210-neoforge-1.21.1.jar
displaydelight-1.7.0.jar
drivebywire-0.3.0.jar
duacan_delight-1.2.0-alpha.jar
easy-villagers-neoforge-1.21.1-1.1.42.jar
ends_delight-2.6.1+neoforge.1.21.1.jar
expandeddelight-0.1.4.jar
extradelight-2.6.6.jar
ferritecore-7.0.3-neoforge.jar
flavor_immersed_daily-2026.9.12.jar
flyhigher-1.21.1-1.0.2.jar
forgified-fabric-api-0.116.15+2.3.5+1.21.1.jar
free_creates_railway.jar
fruitsdelight-1.2.14.jar
fruitydelight-1.0.0.jar
ftb-essentials-neoforge-2101.1.10.jar
ftb-library-neoforge-2101.1.36.jar
ftb-quests-neoforge-2101.1.36.jar
ftb-teams-neoforge-2101.1.11.jar
ftb-ultimine-neoforge-2101.1.15.jar
gan_delight_reborn-2.3.04-neoforge-1.21.1.jar
geckolib-neoforge-1.21.1-4.9.3.jar
guideme-21.1.19.jar
hc2nerf-Neoforge-1.21.1-1.1.2.jar
hotstuff-1.1.7.jar
jasione-1.0.8+1.21.1-neoforge.jar
jei-1.21.1-neoforge-19.57.0.447.jar
kaleidoscope_chinesefood-1.1.12-neoforge+1.21.1.jar
kaleidoscope_contraption-1.0.3.jar
kaleidoscope_dim_wine-1.5.6-mc1.21.1-neoforge.jar
kaleidoscope_doll_workshop-1.0.5-neoforge+mc1.21.1.jar
kaleidoscopetavern-1.2.0-neoforge+1.21.1.jar
kc_sableoptimize-1.0.0.jar
kitchenkarrot-1.21-0.6.3b.jar
kotlinforforge-5.12.0-all.jar
krypton_fnp-neoforge-1.21.1-0.2.28.1-1.21.1.jar
ldlib2-neoforge-1.21.1-2.2.41-all.jar
letsdo-brewery-neoforge-2.1.10.jar
letsdo-brewery-neoforge-2.1.11.jar
letsdo-farm_and_charm-neoforge-1.1.25.jar
letsdo-vinery-neoforge-1.5.4.jar
lithium-neoforge-0.15.4+mc1.21.1.jar
lodestone-1.21.1-1.8.2.jar
maidsoulkitchen-1.21.1-beta-v0.1.4.jar
memguard-1.0.4.jar
mezz_config-1.21.1-neoforge-0.6.3.jar
minersdelight-1.21.1-1.4.5.jar
modernfix-neoforge-5.27.24+mc1.21.1.jar
mooncake_delight-1.6.4-mc1.21.1-neoforge.jar
mysterious_mountain_lib-1.2.15-1.21.1.jar
netmusic-1.5.2-neoforge+mc1.21.1.jar
oceansdelight-neoforge-1.0.4-1.21.1.jar
ordertocook-1.3.6-neoforge1.21.1.jar
packetfixer-3.3.1-1.20.5-1.21.X-merged.jar
pamhc2crops-NEOFORGE-1.21.1-1.0.9.jar
pamhc2fantasy-NEOFORGE-1.21.0-1.0.3.jar
pamhc2foodcore-NEOFORGE-1.21.1-1.0.4.jar
pamhc2foodextended-NEOFORGE-1.21.1-1.0.0.jar
pamhc2trees-NEOFORGE-1.21.1-1.0.9.jar
pamhc2tweak-1.21.1-1.3.2.jar
pineapple_delight-1.2.0-1.21.1-neoforge.jar
polymorph-neoforge-1.2.0+1.21.1.jar
powerful_dummy-21-0.0.10.jar
prickle-neoforge-1.21.1-21.1.11.jar
rainbowcompound-1.21.1-1.3.5.d.jar
resourcefulconfig-neoforge-1.21-3.0.11.jar
rusticdelight-neoforge-1.21-1.7.1.jar
sable-neoforge-1.21.1-2.0.5.jar
shinoyuki_betterautosave-neoforge-0.20.2.jar
simurail-0.1.0+mc1.21.1+ac7f971.jar
sophisticatedbackpacks-1.21.1-3.26.3.2158.jar
sophisticatedbackpackscreateintegration-1.21.1-0.2.0.168.jar
sophisticatedcore-1.21.1-1.5.1.2341.jar
sophisticatedstorage-1.21.1-1.5.91.2127.jar
sophisticatedstoragecreateintegration-1.21.1-0.1.21.209.jar
structure_layout_optimizer-neoforge-1.0.12.jar
sushigocrafting-1.21-0.6.6.jar
sweet-potato-reborn-1.21.1-1.0.1-forge.jar
tacz-neoforge-1.21.1-1.1.8-hotfix-r6.jar
tacz-pack-upgrader-2.1.3.jar
taczaddon-1.1.8.2-neoforge-1.21.1.jar
tea_aroma-1.0.0-beta+neoforge.1.21.1.jar
titanium-1.21-4.0.50.jar
touhoulittlemaid-1.5.3-neoforge+mc1.21.1.jar
towed-1.2.0.jar
tracks-neoforge-1.21.1-1.0.1.jar
trailandtales_delight-2.40.jar
trueuuid-1.3.0-neoforge-1.21.1.jar
vegan-delight-neoforge-1.21.1-1.4.4.jar
windtunnel-1.2.1.jar
xaerominimap-neoforge-1.21.1-26.5.0.jar
xaeroworldmap-neoforge-1.21.1-1.46.0.jar
ysm-2.6.5-neoforge+mc1.21.1-release.jar
zstdnet-1.21.1-neoforge-1.4.8.jar.disable

(The zstdnet-...jar.disable file is inert; also note duplicate-version jars may exist in the folder listing — the authoritative list is whatever NeoForge actually loaded, per latest.log.)

Activity

  1. Jacosvaldo commented on Sep 24, 2026

    @Jacosvaldo

    Same thing on mc26.3-0.26.1-fabric

  2. 2No2Name commented on Sep 25, 2026

    @2No2Name
    Member

    Confirmed for latest lithium on fabric and neoforge

  3. added
    S-confirmed
    on Sep 25, 2026
  4. 2No2Name commented on Sep 25, 2026

    @2No2Name
    Member

    Some chunks do unload via the code path that lithium expects and are thus removed from the dispatcher storage. However, the storage still grows all the time

  5. 2No2Name commented on Sep 25, 2026

    @2No2Name
    Member

    The above commit fixes the issue on latest lithium fabric (didn't test others, the fix should apply to neoforge too).
    The issue was that a chunk load level change between two unloaded/inaccessible levels was interpreted as loading the chunk

  6. changed the title [-][NeoForge] GameEventDispatcherStorage retains LevelChunks forever — memory leak when chunks unload (mixin.world.game_events.dispatch)[/-] [+]GameEventDispatcherStorage retains LevelChunks forever — memory leak when chunks unload (mixin.world.game_events.dispatch)[/+] on Sep 26, 2026
  7. added
    R-pending-release
    on Sep 26, 2026
  8. astelmach20 commented on Sep 26, 2026

    @astelmach20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    R-pending-releaseS-confirmed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions