I noticed that each registered highlighting definition is added to the HighlightingDefinitions collection, and is never removed. Therefore, repeatedly changing the theme in ILSpy creates a small memory leak.
This PR changes this behavior so that registering a named highlighting definition will remove the previous one if it exists.
ILSpy changes themes by calling
HighlightingManager.RegisterHighlighting
to set the new color scheme: https://github.com/icsharpcode/ILSpy/blob/4ebe075e5859939463ae420446f024f10c3bf077/ILSpy/TextView/DecompilerTextView.cs#L1220-L1226I noticed that each registered highlighting definition is added to the
HighlightingDefinitions
collection, and is never removed. Therefore, repeatedly changing the theme in ILSpy creates a small memory leak.This PR changes this behavior so that registering a named highlighting definition will remove the previous one if it exists.