KB0050 - High memory usage for apps\dashboards using UDElement event handlers

KB0050 - High memory usage for apps\dashboards using UDElement event handlers

Affected Versions

- PowerShell Universal 4.1.1 and earlier
- PowerShell Universal 3.9.17 and earlier

Problem

PowerShell Universal apps (v4) and dashboards (v3) will consume gradually more memory when being accessed by users when the dashboard is using a New-UDElement event handler. 
  1. New-UDElement -Tag 'div' -Content {} -Attributes @{
  2.      onClick = {}
  3. }

Root Cause

PowerShell Universal is incorrectly registering the event handlers in a way that prevents them from being removed automatically causing them to grow indefinitely. 

Work Around 1

Restarting the PowerShell Universal app or dashboard will clear the registered event handlers and begin to release memory. Note that memory will be released gradually over time due to .NET garbage collection. 

Work Around 2

Avoid the use of New-UDElement event handlers. Consider using alternative components. For example, New-UDLink with the -Content parameter can replace the usage of OnClick.