2

I have a WPF application that needs to be automatized for the purpose of testing. There is an existing tool that does this using Windows UIAutomation framework.

The problem with that is when I try to access elements on the main app and to trigger them, the memory gets allocated on the main app, and there is no way to force a GC on it. More that this, if an element on a page is not found and there are performed multiple re-trays, there is more memory to be allocated and not freed. I believe the problems come from Find and FindAll methods from AutomationElement class.

The problem seems to be old and there are no generic solutions for it [1][2].

The Automation framework does some caching to have a better access time to the UI elements. One possible solution I have in my mind is to disable the caching of UI elements or to force a cache clear. Have anyone did this previously and can help me with it?

Also, do you have any other solutions to solve the memory leaks problem caused by Windows UI Automation framework?

I did my tests on both a Win7 and a Win10 machine.

[1] https://social.technet.microsoft.com/Forums/lync/en-US/12f6447d-afa3-49b9-9862-013f5d47419a/memory-leak-with-ui-automation?forum=w8itproperf

[2] UIAutomation Memory Issue

vasile_t
  • 372
  • 2
  • 12
  • One [solution](https://stackoverflow.com/questions/18832122/uiautomation-memory-issue) ''After talking to Microsoft customer support, we found the answer to the problem. Internally, WPF gives itself three minutes to respond to a UI Automation event. To do this, it starts off a timer. It appears that even if the event is responded to immediately, the timer does not go away until after the three minutes are up. So, the workaround to the problem is to wait until the timer expires and then do a GC.Collect. Then the memory issue will go away. Not a great fix, but it works for our situation." – vasile_t Jul 17 '18 at 13:27
  • Also, using [PerfView](https://github.com/Microsoft/perfview/releases) to force GC on the target process every 3 minutes helps. – vasile_t Jul 17 '18 at 13:30

0 Answers0