[Cocos Creator 3.8.0] set skeletonData to null cause memory leak

Hi, I have found an issue about Spine. When set skeletonData to null, any subsequence set data other than null will cause memory leak.
My experiment like this:

@ccclass("Test")
export class Test extends Component {
	@property(sp.Skeleton) ske: sp.Skeleton = null;
	@property(sp.SkeletonData) skeData: sp.SkeletonData = null;

	private _turn = 0;

  start() {}

  update(deltaTime: number) {
		if (this._turn === 0) {
			this.ske.skeletonData = null;
		} else {
			this.ske.skeletonData= this.skeData;
			this.ske.setAnimation(0, 'idle', true);
		}
		this._turn = (this._turn + 1) % 2;
	}
}

run this for a while the heap memory will always increase
image

Here is my demo project
TestSpineLeak.zip (6.6 MB)

This issue will be fixed in the 3.8.2 version, and the official PR is: https://github.com/cocos/cocos-engine/pull/16384.

Here is a temporary solution:

Download the spine wasm file and place it in the engine folder. The folder path is as follows:
spine.zip (348.5 KB)

C:\ProgramData\cocos\editors\Creator\3.8.0\resources\resources\3d\engine\native\external\emscripten\spine

After that, refer to the temporary PR to modify the engine code:

Or download and replace the file directly. The folder path for replacement is as follows:
spine.zip (33.5 KB)

C:\ProgramData\cocos\editors\Creator\3.8.0\resources\resources\3d\engine\cocos\spine

Finally, click the compile engine button and wait for the console to display ‘Quick Compile’.

图片

Hi, this issue is fixed. However, I find another issue with spine cause memory leak.
Our game use a lot of spine. I add about 40 spine instance to scene (cache mode realtime, some spine have enable batch). The memory using will still increase after some interval (30s - 1 min).

My scene set up look like this:
image

It seem your team have aware that spine is causing memory leak before this first post. Can you help me to fix this?

Hello, I tested the new issue you mentioned and did not find any abnormalities. Please provide me with the test project.

Here is the test project
Spine3-8-leak.zip (261.3 KB)

Here is heap snapshots I capture for 1 minute each (total 10 min)

1 Like

I tested this issue in the repaired engine and it worked fine. I uploaded my engine, you can download it and use it. It is based on Creator 3.8.0.

https://docs.cocos.com/creator/manual/en/advanced-topics/engine-customization.html#4-modifying-the-engine-path

http://download.cocos.org/CocosTechnicalSupport/discussIssues/59642/engine.zip

Hi, I have tested with this repaired engine and the issue still persists. I have downloaded the engine, change the path, restart the editor, select Compile the Engine, clear code Cache. Am I missing something?

It looks like there are no missing steps. It may be easier to solve the problem when Cocos Creator v3.8.2 is released.

Ok, I will stick with Cocos 3.7.2 for now :rofl: