Garbage Reduction

From Kerbal Space Program Wiki
Revision as of 05:47, 1 October 2016 by Henrybauer (talk | contribs) (What is garbage, and why is it bad?)
Jump to: navigation, search

What is garbage, and why is it bad?

C# is a garbage-collected language, which means that the programmer doesn't have to worry about deleting variables when done with them; the system will do it automatically.

However, the way it does this is by freezing the system and then walking through the list of variables and removing the unused ones ("garbage" variables). This can cause stutters, and the stutters will be more frequent and longer the more garbage there is.

Measuring garbage production

MemGraph can show you how much garbage KSP is creating. It is not broken down by mod, so to test a specific mod you'll need a copy of KSP with only that mod installed.

Best practices to avoid creating garbage

  • avoid foreach
  • using System.Linq