Added a forced garbage collection to fix an Out Of Memory bug that results from using .Net’s Regex functions (which do not properly reclaim memory)

This commit is contained in:
John Jenko 2015-11-20 20:59:25 +00:00
parent f4e7d7bfe5
commit ba3bceadae

View File

@ -2517,6 +2517,7 @@ namespace Volian.Controls.Library
if (SelectionStack.Count == 0) if (SelectionStack.Count == 0)
_SelectionStack = null; _SelectionStack = null;
Select(selection.SelectionStart, selection.SelectionLength); Select(selection.SelectionStart, selection.SelectionLength);
selection = null;
} }
public class SelectionData public class SelectionData
{ {
@ -2572,6 +2573,7 @@ namespace Volian.Controls.Library
} }
private void FindLinks() private void FindLinks()
{ {
//int oldRegexCacheSize = Regex.CacheSize;
string str = Text; string str = Text;
_LinkLocations = new List<LinkLocation>(); _LinkLocations = new List<LinkLocation>();
MatchCollection matches = Regex.Matches(str, @"<START](.*?)[[]END>", RegexOptions.Singleline); MatchCollection matches = Regex.Matches(str, @"<START](.*?)[[]END>", RegexOptions.Singleline);
@ -2586,6 +2588,9 @@ namespace Volian.Controls.Library
match.Value, matchrtf.Index, matchrtf.Length, thisLink); match.Value, matchrtf.Index, matchrtf.Length, thisLink);
_LinkLocations.Add(thisLink); _LinkLocations.Add(thisLink);
} }
//Regex.CacheSize = 0;
GC.Collect(); // there is a memory leak in Regex this fixes it.
//Regex.CacheSize = oldRegexCacheSize;
} }
private LinkLocation FindBetweenLinks() private LinkLocation FindBetweenLinks()
{ {