• RuntimesBugs
  • MonoGame Runtime is creating a lot of GC pressure

Hey, I am currently working on an engine that should support Spine animation. I tried to render 200x the default "Spine boy on a raptor" scene and after a few seconds of experiencing stutters and micro lags I stop my process and get those hints from my IDE (see screenshots, first from my call, second from the Spine)

As you can see the runtime is somehow re-creating tons of arrays very often which are all stored in the heap so they have to get GCed.

Did anyone encounter this issue?

![runtime).](

Related Discussions
...

It seems like you are experiencing significant garbage collection (GC) pressure when rendering multiple instances of the "Spine boy on a raptor" scene in your MonoGame engine. This issue might be related to the frequent creation of new arrays or objects, which can lead to increased memory allocation and subsequent GC activity. A similar issue has been noted in other contexts, such as with Unity, where JSON deserialization and other operations can produce excessive garbage. One potential solution is to ensure that you are using the most efficient data formats and minimizing unnecessary object creation. For instance, using binary formats instead of JSON can reduce garbage production. Additionally, reviewing your code to ensure that objects are reused rather than recreated can help alleviate GC pressure. If the problem persists, consider profiling your application to identify specific areas where memory allocations are high and optimize those parts of your code.

  • Helroth ответили на это сообщение.

    Spinebot The issue is not the loading, it's the runtime / rendering of the Spine animations. So I don't have control over how the Spine runtime is dealing with memory without writing my own runtime.

    Helroth добавил(а) Bugs тег .

    Don't mind Spinebot when he's occasionally useless. 😬

    In this code:
    EsotericSoftware/spine-runtimesblob/4.2/spine-monogame/spine-monogame/src/SkeletonRenderer.cs#L154
    It looks like our intent was to assign back to this.vertices rather than only the local. Try:

    if (vertices.Length < vertexCount) this.vertices = vertices = new float[vertexCount];

    My colleagues will be along Monday to dig in and commit a fix!

    • Helroth ответили на это сообщение.

      Nate Hey, thanks for your answer. I tried to re-write some parts to use Span<float> and stuff but that would be a bit too time-consuming.
      Your solution worked and it seems I don't get any GC while running my test scene. Cool! Looking forward to the official fixing commit. 🙂

      • Nate оценил это.

      Hey thanks for the quick fix. But unfortunately it did not work and we still have a lot of heap garbage, also after allying your fix (@Nate His fix worked though).

      @Helroth Unfortunately I could not reproduce your issues reported on the issue ticket, all example scenes render without any issues. Are you sure you're not having leftover changes of your local modifications?

      Anyway, I've reverted the preceding commits and fixed using Nate's original bugfix. We hope that this fixes the issue on your end now.