EsotericSoftware / spine-runtimes

2D skeletal animation runtimes for Spine.
http://esotericsoftware.com/
Other
4.42k stars 2.92k forks source link

[ts][pixi-v8] Spine objects isn't destroyed from memory #2678

Closed nikollaidemchenko closed 1 week ago

nikollaidemchenko commented 1 week ago

this.gpuSpineData from SpinePipe keeps links to spines after they was destroyed

This method wasn't called.

    destroyRenderable (spine: Spine) {
        // TODO remove the renderable from the batcher
        this.gpuSpineData[spine.uid] = null as any;
    }

Fix:

add

    if (!Object.values(gpuSpine.slotBatches).length) {
      spine.on('destroyed', this.destroyRenderable.bind(this, spine));
    }
to addRenderable method
  addRenderable(spine: Spine, instructionSet: InstructionSet) {
    const gpuSpine = (this.gpuSpineData[spine.uid] ||= { slotBatches: {} });

    if (!Object.values(gpuSpine.slotBatches).length) {
      spine.on('destroyed', this.destroyRenderable.bind(this, spine));
    }
    ...
    }

add spine.off('destroyed') to destroyRenderable method

  destroyRenderable(spine: Spine) {
    this.gpuSpineData[spine.uid] = null as any;
    spine.off('destroyed');
  }
davidetan commented 1 week ago

I was already fixing the memory leak this morning, see this commit.

I wanted to test it a little more before merging. I'll probably release it today 👍

davidetan commented 1 week ago

We released this in 4.2.65. Even though we were already addressing the issue, I appreciate you reporting this.