Memoryleak with ObservableCollection
I noticed that when I add and remove items from an ObservableCollection, memory usage goes up quickly. If I don't replace the items, but reuse existing items, memory usage remains stable.
Usually this won't be an issue, but in this case, the collection is updated whenever the GPS location changes, so this happens quite often.
Is this a known issue, and if so, is there a workaround?
0
-
Hi Berend,
I did a little test with this. I gathered a collection of a couple hundred features and I added and removed them from an ObservableCollection 100 times each, calling new Feature() each time so that I am not just reusing the same objects.
While this does cause an immediate spike in memory usage, it appears that all of the objects created (and no longer in use) can be garbage collected by the browser. Therefore I don't see any evidence for a memory leak caused by the operation of ObservableCollection.
It is important to note that the memory will not necessarily be immediately freed, but it should be eventually, and will be immediately if the memory is needed by something else. The exact timing of this is up to the implementation of the JavaScript garbage collector in the browser you are using.
I recommend using the Chrome debugger tools to analyse memory usage in your own environment to see if there are any problems. Follow the instructions here:
https://developers.google.com/web/tools/chrome-devtools/memory-problems/
Start a performance snapshot with memory enabled, perform the process that you are concerned about, then use the button in the performance tab to force a garbage collection before you finish profiling. You should see memory usage spike up as the operation occurs, then decline to more or less the same level as before after forcing the garbage collection.
Also worth noting -- while Edge, Firefox and Chrome contain efficient and up-to-date JavaScript garbage collectors, the implementation in all versions of IE has known issues and bugs. Some of these can and do cause memory leaks while using our viewer, but these should not occur in other browsers.
- Jonathan0
Please sign in to leave a comment.
Comments
1 comment