I have a custom widget built for Cityworks using ArcGIS API 4.x for Javascript: https://developers.arcgis.com/javascript/latest/custom-widget/index.html
The widget creates a featurelayer client side and then populates it using a web socket. The issue I'm experiencing is that the memory usage of the widget keeps increasing until the app crashes with the dreaded 'Oh Snap!' error. There was an older version of the application that was developed using ArcGIS JavaScript API 3x that used the same concept but it does not have the memory usage issue.
One thing I have noticed is that even after I stopped the web socket, which also calls the destroy() method on the featurelayer, the memory usage as shown by Task Manager stays the same, even after an hour.
Is there something about the custom widget framework that can be used to force garbage collection once a featurelayer or other memory intensive objects are no longer needed? Could the custom widget framework be interfering with garbage collection?