Jerry

I noticed that in our game Idle Miner Tycoon we have a Memory leak when creating new Spine Objects and destroying them. So i made a new scene with a very simple Setup to pinpoint the problem:
  • empty scene with only a spawner
sceneSetup.PNG

  • Spawner scrip that just instantiates a spine object and basically only calls SkeletonAnimation.Initialize and then destroys that gameObject immediately again
scriptSetup.PNG


What i found is that the number of meshes and total objects in the scene grows dramatically over time .. and it doesn't seem like it gets garbage collected at all.
meshcount.PNG


Do i need to explicitly destroy every component or something like that ?

- Why we are doing this -

We implemented a system which lets the player change the cosmetics (appearance and animation) of the mine workers in the game. Everytime the player changes the cosmetics we change the spine ScriptableObject and then call initialize.
Should we maybe change our system to use skins when changing the cosmetics?
Jerry
Posts: 1

Pharan

1. Thanks for sharing your findings!
The leak is strange behavior.

What's a SpineAnimator? We don't have that class in the official runtime.

2. We've already implemented manual destroy on the meshes.
Spine-Unity rendering are supposed to implement OnDestroy, which ultimately calls this:
public void Dispose () {
if (mesh != null) {
#if UNITY_EDITOR
if (Application.isEditor && !Application.isPlaying)
UnityEngine.Object.DestroyImmediate(mesh);
else
UnityEngine.Object.Destroy(mesh);
#else
UnityEngine.Object.Destroy(mesh);
#endif
}
mesh = null;
}
If this is indeed caused by one of our classes, it may be worth investigating if the hideflags are causing this.
In SpineMesh.cs, we centralize whenever Spine creates a dynamic mesh, and the hideflags are set to this const.
internal const HideFlags MeshHideflags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor;
3.
By "spine ScriptableObject", do you mean the SkeletonDataAsset? That doesn't quite make sense.
But immediately, I would recommend using runtime skin composing, rather than always reinitializing existing SkeletonAnimation/SkeletonRenderer.

-- 19 Sep 2017 1:33 pm --

Before making any changes to the current version of the Spine-Unity runtime, I can't seem to replicate the results. Seems like your setup has something special about it that might be causing the leak.
User avatar
Pharan

Pharan
Posts: 4493


Return to Unity