Featurelayer Destroy not Freeing Memory

368
4
10-13-2022 02:12 PM
MichaelWen_Timmons
New Contributor III

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? 

4 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

Can you please provide a test case for this one so that we can take a look at it. Thanks.

0 Kudos
MichaelWen_Timmons
New Contributor III

I am not sure I can provide a test case as it is a very large application. I can say that it works fine locally when run on a vite server but when deployed as a Cityworks plugin the memory issue occurs.

To elaborate, the app creates a Featurelayer client side, then add/remove features to it using applyEdits in response to a web socket. The number of features added to the layer can vary over time but mostly stays at a plateau. However the memory usage keeps increasing until the app crashes.

So my question boils down to - is there a way to 'force' maps, mapviews or featurelayers to free up unused memory? 

0 Kudos
mkennedy
New Contributor

Same here, after dynamic loaded data from enrich endpoint, we redrawing feature layer by destroying it, and creating new one with new data, when amount of data is large(especcially on low scale levels) memory limit exceeded and error appear(oh snap). we are using arcgis/core 4.19.3

0 Kudos
UndralBatsukh
Esri Regular Contributor

HI there, 

Which version of the API are you all using? You say large amount of data. You how many features? Geometry type? Maybe number of attributes? Can you please give me some ideas to set up a test? 

Thanks,

0 Kudos