Memory leak when destroying objects with UdonSharpBehaviours
available in future release
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
ShingenPizza
i can't see it being mentioned in the open beta changelog, but it looks like the fix has been included within it, so thanks for that.
if the person responsible, or someone else familiar with Udon internally is reading this and would like to handle this other kinda serious, workaroundable but fundamental issue that Udon's had for over 5.5 years, i'd appreciate it a lot too https://feedback.vrchat.com/udon/p/branches-decompose-variables-to-null-in-certain-scenarios
i'd be happy to provide examples/explanations of at least 1 of the cases.
This post was marked as
available in future release
Sotalo
I've also discovered the destroy function doesn't work using Udon Graph. Instantiating an object and calling destroy on that object doesn't appear to fire an event, not even an error or log, and the duplicates remain. I'm disabling them, but this can cause a serious memory leak as the UI instantiates a list of buttons based on the number of players in the instance.
_

_tau_
updated the status to
tracked