Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Bug Report: meshes accumulate in memory without being destroyed

A topic by Draque created Jan 04, 2026 Views: 221 Replies: 2
Viewing posts 1 to 3

The class STMMaskableGraphic creates Mesh objects but never destroys them, and they aren't handled by garbage collection. I'm still on an older version of STM, so I am not sure whether this has been cleaned up already, but it seemed like it's worth reporting.

Since _workerMesh is instantiated on every OnEnable(), I added this to the bottom of the OnDisable() method:

if (_workerMesh != null)
    Destroy(_workerMesh);

Since _workerMeshes is only populated and never depopulated (and I don't fully understand the full lifecycle for its contents), I just defaulted to adding the below code on the Unity destructor for the class.

protected override void OnDestroy()
{
    base.OnDestroy();
    foreach (var mesh in _workerMeshes)
    if (mesh != null)
        Destroy(mesh);
}

Developer

Ah, good catch!! I'll add this for the next update, should hopefully get that this week. I think I was so excited by STMMaskableGraphic *actually working* that I forgot to check GC... oops.


Should hopefully be fine since it's just OnEnable/OnDisable, but I remember it was very specific about how the worker meshes needs to be used, other techniques just wouldn't work.

I did some heavy lifting tests with it and dug pretty deeply into how it's being called and ran into no issues so far. I think that if anything, it might be possible to be more aggressive with how the contents of _workerMeshes is cleared... but also that doing so wouldn't be necessary unless there was a single object which persisted for very long periods of time and for some reason had insane numbers of meshes generated for it.