[SOLVED] Memory Leaks of Spine Component?

Hi guys

Sadly I’m back with another issue regarding memory leaks, this time concering your spine library. We noticed that we still have quite some memory leaks in our projects, and on further investigation, we noticed that our spine entities do not get freed in the memory. I used the same project I posted last time, added two new scenes with one spine object each and you can switch between them.

I used the Memory Allocation Timeline to look at the memory, which looks like this:

Each spike represents the total newly allocated memory when changing the scene. After changing the scene again, part of the spike becomes grey, which displays how much memory was freed, while the blue part represents the memory that still stays allocated and cannot be freed.

I then took a closer look at what kind of objects couldn’t be freed:

The top two types of object (“Func” and “t”) regarding their retained size are all linked to the spine object.

We are working quite a lot with spine in our games, so leaking about 0.5 MB (depending on the complexity of the spine of course) per spine object everytime we switch a scene is quite a lot. It would be awesome if you could take a look at this.


Hi @AliMoe,

I don’t have much experience with how Spine and the Playcanvas Spine plugin works, but I do know that changing scenes won’t release the assets used automatically.

There is a manual step involved where the developer must unload the assets used before loading the new hierarchy.

@will @vaios may know in more detail how the Spine plugin functions.

Hi @Leonidas

I followed Dexter Deluxe’s topic and read your points, but I don’t think this is a VRAM related issue. The timegraph shows, that new memory gets allocated each time I switch the scene. The VRAM though should stay the same size once all assets are loaded.

Concerning the unloading of assets: Do assets contain references to the objects which use them? Do we really need to unload the assets in order to free entities? Seems a bit far fetched though, and doesn’t sound like a good design :sweat_smile:

No, it is the other way around as expected: assets are used/referenced by components that are attached to entities.

You are right that this doesn’t concern VRAM, it concerns τηε garbage collector not dropping handles to memory holding entities etc.

Sorry I can’t be of more help, this is something to be debugged on the un-minified spine plugin source code.

I will look into that one too.

From quick glance, looks like there is subscription to assets change events, but when related entity is destroyed, it does not unsubscribes from such event. So keeping reference to entity (scope for event handler) in assets _callbacks. This prevents from entities being freed.

Thank you for profiling and reporting an issue!

No Problem.
Thanks for looking into that issue, looking forward to what you find out :slight_smile:

Hey, not trying to be annoying, just being curious if you already got to work on this issue? :wink:

Shall I open an issue in the pc-spine repo, or can I help myself on fixing the issues?

1 Like

Yes please.

I’ve created a PR that fixes two memory leaks: https://github.com/playcanvas/playcanvas-spine/pull/24

1 Like

This has now been merged (thanks @moka!).

1 Like

Cool, thanks :grin: