I don’t mean everything, but I actually mean most things.
I’m the creator of a mod, RustEssentials, for a Unity game called Rust. RustEssentials is a C# assembly compiled into a .DLL using Visual Studio. I then load the .DLL at a certain point in server initialization and call a static method in RustEssentialsBootstrap.cs to start up the mod. Outside of RustEssentialsBootstrap, I use static for nearly everything: fields, properties, methods, classes, etc. For the past few months, I’ve been trying to figure out what I need to do to clean up a crashing issue that only occurs when using my mod. My assumption is that I have some sort of memory leak in my mod. Admittedly, I was an amateur when I first started the mod so the code is disorderly and practically an eye sore. Despite this, I feel like it’s never too late to fix what I did wrong.
Essentially, I need help figuring out what is wrong with what I have and what I need to do to fix the crashing issue I’ve been having.
Should I not use foreach? Should I manually do GC.Collect? If so, how often? What is the significance of GC.Collect() vs GC.Collect(0) (I saw this somewhere but didn’t really understand the objective.)? Is it bad to use StartCoroutine an abundant amount of times? Should StartCoroutines have short lifespans or is it okay to keep them running over a long period of time? Should I swap out all StartCoroutines with the creation of new [worker/background] threads? Should I consider using StringBuilder instead of all the string concatenation I do? If I’ve made a horrible mistake with using static everything, what is the best way to fix my problem? How should I reformat things? What should I do to properly dispose of UnityEngine.MonoBehaviour objects that I create? Is the sky blue?
You can view the source of my mod at GitHub.
I’ve been running into a brick wall for quite some time now. Thanks for helping, I greatly appreciate any helpful feedback and advice.