Skip to content

Memory leak / chunk retention when repeatedly entering and leaving custom dimensions (especially touhou_little_maid_spell:the_retreat) #1322

Description

@REDSTONE440

Description

I am experiencing a severe memory leak that appears to be related to dimension switching, particularly involving custom dimensions like touhou_little_maid_spell:the_retreat. The leak manifests as a continuous increase in LevelChunk objects that are never garbage‑collected, leading to rapid memory exhaustion and severe server TPS drops.

The issue is reproducible in a modded environment with Sable (2.0.3) and several other mods, but the common factor is that every time I enter or leave a dimension, Sable creates a physics pipeline for that dimension, and when the dimension is unloaded, the associated chunks and physics data seem to persist in memory.

In addition, the log is flooded with errors like:

Failed to apply tag physics properties. Unknown block: copycats:copycat_step
Failed to apply tag physics properties. Unknown block: copycats:copycat_catwalk

These errors occur for every dimension Sable initialises, and while they might be harmless in themselves, they suggest that Sable is trying to apply physics to blocks that are not registered or are not present, which could be a symptom of a deeper cleanup issue.


Steps to Reproduce

  1. Install Sable (2.0.3) and any mod that adds custom dimensions (e.g., touhou_little_maid_spell 1.8.1) and a memory monitoring mod like AllTheLeaks (optional but helpful).
  2. Load a world and enter a custom dimension (e.g., touhou_little_maid_spell:the_retreat).
  3. Return to the overworld, then re‑enter the custom dimension repeatedly (about 5–10 times).
  4. Monitor memory usage (using F3 or /atl force_refresh).
  5. Observe that the memory footprint grows with each cycle and does not shrink back, even after leaving the dimension.

Actual Behaviour

  • Memory usage increases steadily (from ~5 GB to >12 GB within 10 minutes) and the Diff value in AllTheLeaks keeps rising.
  • The number of LevelChunk instances reported by AllTheLeaks increases after each dimension hop.
  • Server performance degrades dramatically, with warnings like:
    Can't keep up! Is the server overloaded? Running 39394ms or 787 ticks behind
    
  • The following error appears repeatedly in the log for every dimension:
    [ERROR] [dev.ryanhcode.sable.Sable/]: Failed to apply tag physics properties. Unknown block: copycats:copycat_step
    [ERROR] [dev.ryanhcode.sable.Sable/]: Failed to apply tag physics properties. Unknown block: copycats:copycat_catwalk
    

Expected Behaviour

After leaving a custom dimension, all chunk references and physics data associated with that dimension should be fully released, allowing the garbage collector to reclaim the memory. The Unknown block errors should not occur, or at least they should not affect the life‑cycle of dimension unloading.


Environment

  • Minecraft version: 1.21.1
  • Mod loader: NeoForge 21.1.233
  • Sable version: 2.0.3
  • Java version: OpenJDK 21.0.11+10-LTS
  • OS: Windows 11
  • Other relevant mods: touhou_little_maid_spell (1.8.1), Copycats+ (3.0.4), AllTheLeaks (1.1.9)

Logs

Click to expand relevant log excerpts
[15:03:37] [Render thread/INFO] [AllTheLeaks/]: B: 5236MB / C: 12342MB / Diff: +7106MB
[15:03:37] [Render thread/INFO] [AllTheLeaks/]: Memory Leaks detected:
[15:03:37] [Render thread/INFO] [AllTheLeaks/]: | ChunkAccess:
[15:03:37] [Render thread/INFO] [AllTheLeaks/]: |- LevelChunk (minecraft): 5972

[15:15:11] [Server thread/INFO] [dev.ryanhcode.sable.Sable/]: Creating physics pipeline for ResourceKey[minecraft:dimension / touhou_little_maid_spell:the_retreat] using RapierPhysicsPipelineProvider
[15:15:11] [Server thread/ERROR] [dev.ryanhcode.sable.Sable/]: Failed to apply tag physics properties. Unknown block: copycats:copycat_step
[15:15:11] [Server thread/ERROR] [dev.ryanhcode.sable.Sable/]: Failed to apply tag physics properties. Unknown block: copycats:copycat_catwalk

[15:05:08] [Server thread/WARN] [net.minecraft.server.MinecraftServer/]: Can't keep up! Is the server overloaded? Running 2861ms or 57 ticks behind
[15:08:17] [Server thread/WARN] [net.minecraft.server.MinecraftServer/]: Can't keep up! Is the server overloaded? Running 39394ms or 787 ticks behind

Additional Context

  • The issue seems to be more pronounced when custom dimensions that are created on‑the‑fly (like the UUID‑suffixed retreat dimension) are used. Sable creates a new physics pipeline for each such dimension, and they appear to remain in memory even after the dimension is closed.
  • The Unknown block errors might be a side effect of Sable trying to apply physics to blocks that are not present in the current world (e.g., Copycats+ blocks are not loaded in that dimension). This could lead to incomplete initialisation, preventing proper cleanup.

I would appreciate any insight into whether Sable's dimension‑cleanup logic can be improved, or if there is a configuration option to avoid creating physics pipelines for dimensions that do not require them.

Thank you for your excellent work on Sable.
This report was summarized by AI based on the logs and reviewed by me. Hope you don’t mind.

Game Log

https://mclo.gs/eqRqmYE

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions