Difference between revisions of "Garbage Reduction"

From Kerbal Space Program Wiki
Jump to: navigation, search
(Created page with "==What is garbage, and why is it bad?== ==Measuring garbage production== [http://forum.kerbalspaceprogram.com/index.php?/topic/139128-113-memgraph-10010-with-stutter-reductio...")
 
(What is garbage, and why is it bad?)
Line 1: Line 1:
 
==What is garbage, and why is it bad?==
 
==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==
 
==Measuring garbage production==

Revision as of 05:47, 1 October 2016

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