DrawingManager's IDrawGizmos causing memory leak?

I’m noticing a bunch of resources apparently kept alive by DrawingManager. For example, here’s some Memory Profiler results in my project:

I saw another post here that suggested simply calling GameObject.Destroy(DrawingManager.instance.gameObject);, but that isn’t a viable fix, since the references are held by a static List in DrawingManager, not by the DrawingManager instance.

I’m was wondering if anyone else had run into this. For me this is easy to reproduce: I just load any level with a NavmeshCut on it, then leave the level. The reference will be kept alive, as per the screenshot.

Is there a proper way to clean the DrawingManager static data when I load a new scene? I’m going to just try clearing all of the static collections in DrawingManager, but I don’t know if that will have unwanted side effects. Mostly just looking for guidance or reporting an issue here.

Would you be able to post more detailed reproduction steps for this? I want to make sure I’m able to reproduce it myself

This was the result of captures in the Memory Profiler tool, the first snapshot taken at my main menu, and the second taken after opening several levels (via LoadSceneAsync) and returning to the main menu. The levels I loaded contained gameObjects that has NavmeshCut components on them.

It seems that those NavmeshCut objects get picked up by the DrawingManager, and store a reference in a static list. There was a forum post about simply calling Destroy on the DrawingManager, which was supposed to correct this. But destroying the DrawingManager doesn’t clear that static list. The lists are only cleared when a new DrawingManager is instantiated.

So, it’s weird that this class keeps references alive to any objects that have NavmeshCuts on them (and presumably any other classes with ALINE gizmos?). It never cleans itself up, and relies on end-users to know they need to Destroy the DrawingManager from time to time to try to clear these allocations. It seems the drawing manager should periocally check if its references have been destroyed, and clear those static lists to avoid being the reason they’re kept alive in memory.

Gotcha. I’ll let Aron know about this and have ask him to take a more close look at it. Thanks for letting us know :+1: