Skip to content

Feature request: detach chunks from unloaded world instances to reduce memory retained by stale references #201

Description

@KamikotoTkach

Problem

When using AdvancedSlimePaper with many dynamic worlds, unloaded world instances can still retain a large amount of memory if some plugin keeps a strong reference to the old world object.

In practice, many Minecraft plugins are not designed well for dynamically created and unloaded worlds. They may accidentally keep references to World, Chunk, Location, scheduled tasks, listeners, cached objects, or other objects connected to a world. Because of this, even after the world is unloaded, the old world instance may still be reachable from GC roots through a third-party plugin.

The issue is that the retained world instance appears to keep strong references to its loaded chunks and related chunk data. As a result, a single stale world reference can retain much more memory than just the world object itself.

This becomes a serious problem when working with many temporary or instanced worlds. In my case, memory pressure already starts becoming noticeable at around 100 retained unloaded worlds. Ideally, accidentally retained unloaded world objects should be cheap enough that even a much larger number of stale world references would not immediately fill the heap.

Proposed solution

After a Slime world is unloaded, the world instance should release/detach as much heavy runtime state as possible, especially strong references to chunks and chunk-related data.

In other words, once the world is no longer loaded, the old world object should become more like a lightweight "dead shell" / placeholder:

  • no strong references to loaded chunks;
  • no strong references to chunk sections, entities, block entities, ticking data, or other heavy per-world runtime state where possible;
  • only minimal metadata required for diagnostics or safety checks should remain;
  • any attempt to use the unloaded world instance should either fail safely or behave consistently with Paper’s existing unloaded-world behavior.

Optional diagnostic command

It would also be very useful to have a diagnostic command for finding unloaded world instances that are still being retained in memory.

For example, a command could list unloaded Slime worlds that are no longer registered as active worlds, but whose old world instances are still reachable.

This would make it much easier to identify problematic third-party plugins that keep references to unloaded worlds or other stale world-related state.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions