Today I noticed that a little program I made triggered GC quite often during the first 10~20 seconds of the programs lifetime. After which it barely triggers ever again.
During this period of time only 1 function runs, which is the one below. Obtaining ~2k of file paths, and filtering out most of them.
public static string[] FilterFiles(string path)
{
// Fetch the files from given directory
var files = Directory.GetFiles(path);
// Delete all files that are to small
foreach (string file in files)
{
string fullFile = default(string);
try
{
fullFile = File.ReadAllText(file);
}
catch
{
continue;
}
if (fullFile.Length < Settings.MinimumFileSize)
{
File.Delete(file);
}
}
// Obtain the new list without the small files
List<string> cleanFiles = new List<string>(Directory.GetFiles(path));
List<string> cleanReturn = new List<string>(Directory.GetFiles(path));
// Remove files we have handled before
foreach (string file in cleanFiles)
{
if (File.Exists(Settings.ExtractFolder + "\\" + file.Substring(file.LastIndexOf('\\') + 1) + "_Extract.xml"))
{
cleanReturn.Remove(file);
}
}
return cleanReturn.ToArray();
}
Is it normal for GC to trigger this often in this period of time?