Memory leak when destroying objects with UdonSharpBehaviours
ShingenPizza
While spending time in my (private) world with a bunch of friends, some started crashing, and we noticed that VRC is using huge amounts of RAM.
I traced the issue to a script that frequently recreates a UI list, where every entry is an instantiated object with an UdonSharpBehaviour script controlling the UI contents.
As it turns out, using Destroy() on an object with an UdonSharpBehaviour does not seem to free the memory - my guess is that the overarching Udon system is still keeping references to every instance of a script that ever existed (for example to run their Update()s?).
The memory gets freed shortly after leaving the world, so it's not the end of the world, but i would still appreciate fixing it.
As a workaround (and, frankly, just a better/more performant solution) i no longer destroy the entries, but reuse the old ones, and just hide the ones that are not needed, but that doesn't change the fact that it's a bug that other people may be affected by. It may be the reason behind many other unspecified memory leak reports here.
I created a world that presents the issue
Functionally, it just performs
Destroy(Instantiate(template));
100 times per an execution of a FixedUpdate() when the cube/button gets activated (green).The template of the left button is just an empty GameObject, while of the one on the right contains an additional empty UdonSharpBehaviour.
Log In