I call the following API using c# over and over again using a timer. All it does is that it gets the top level windows on my desktop and does nothing else.
AutomationElementCollection desktopChildren = AutomationElement.RootElement.FindAll(TreeScope.Children, Condition.TrueCondition);
When you run the console application on a Windows 10 machine and check the task manager the memory consumption is stable. On Windows 11 the memory consumption just keeps increasing it.
This is my full code for the console application. To reproduce it just copy paste this code in a Visual Studio Console Application and add the necessary refs using (Ctrl + .)
using System;
using System.Threading;
using System.Windows.Automation;
class Program
{
private static Timer stateTimer;
static void Main(string[] args)
{
stateTimer = new Timer(Callback, null, 0, 1000); ;
Console.ReadLine();
stateTimer.Dispose();
}
static void Callback(object state)
{
AutomationElementCollection desktopChildren = AutomationElement.RootElement.FindAll(TreeScope.Children, Condition.TrueCondition);
}
}
What I expected is that the memory consumption would be stable in Windows 11 too, but that is not the case.
Any suggestions or pointers you might have is gladly welcome. Thank you.