mojira.dev
MCPE-229293

[Script API] Memory not released when calling getParticipants() on scoreboard

Using world.scoreboard.getObjective() together with getParticipants() in scripts causes memory allocated for participants to remain in the engine, even after participants are removed or the scoreboard is deleted. Memory growth occurs regardless of whether calls are executed once or repeatedly. Experimental results show that using in-game commands or mcfunctions to create/reset scoreboard entries does not cause memory growth, which directly indicates that the problem originates from the getParticipants() function in the Script API. Memory is only released after reloading the script.

Steps to Reproduce:

  1. Create a script with the following structure:

    import { ScoreboardObjective, system, world } from "@minecraft/server";
    
    let sub: number | null = null;
    let obj: null | ScoreboardObjective;
    
    system.afterEvents.scriptEventReceive.subscribe((t) => {
        obj =
            world.scoreboard.getObjective("test") ??
            world.scoreboard.addObjective("test");
        if (t.message == "stop") {
            if (sub) system.clearRun(sub);
        } else if (t.message == "start") {
            sub = system.runInterval(() => interval());
        } else if (t.message == "test") {
            interval();
        }
    });
    
    function interval() {
        if (!obj) return;
        obj.getParticipants(); // memory leak occurs here
    }
    
  2. Prepare a mcfunction to create multiple scoreboard entries:

    scoreboard players set "0" test 1
    scoreboard players set "1" test 1
    ...
    scoreboard players set "999" test 1
    
  3. Run the mcfunction repeatedly with command blocks: scoreboard players reset * test -> function ....

    • Observe that memory usage remains stable.

  4. Trigger the script via "start" message or "test" message.

    • Memory usage rapidly increases in Task Manager or equivalent tool.

Expected Behavior:

  • Memory allocated for scoreboard participants should be released after operations like:

    • Removing participants.

    • Resetting the scoreboard.

    • Stopping the script.

Actual Behavior:

  • Memory continues to grow when getParticipants() is called from scripts.

  • Memory is not released even if participants are removed or scoreboard entries are reset via commands.

  • Only reloading the script frees the memory.

Environment:

  • Script API (@minecraft/server-2.3.0-beta)

  • Observed on Windows 11 / Task Manager

  • This issue also occurs on Bedrock Dedicated Server.

Attachments

Comments 2

[media]

This is the behavior pack for testing.

New test pack (using mcfunction to reproduce the issue)

[media]

XiaoYangx666

(Unassigned)

Unconfirmed

Multiple

Windows 11

1.21.111, 1.21.113 Hotfix

Retrieved