none
v8 Web control - best practices of 'clean' the resources when map is not needed RRS feed

  • Question

  • Hello!

    In our application we have several screens where map is loaded. When we leave such a screen the corresponding DOM elements are removed.

    What are the best practices of cleaning up all resources used by the Map so that there won't be any leaks?

    Should we remove manually event handlers attached to the Pushpins/Infobox?

    Should we remove manually all map.entities?

    Thanks in advance.

    Monday, October 31, 2016 4:44 PM

Answers

  • Use the maps dispose function. This will go through and clear all the entities, layers and events from the DOM and memory. No need to manually remove these.

    [Blog] [twitter] [LinkedIn]


    • Proposed as answer by Ricky_Brundritt Monday, October 31, 2016 7:03 PM
    • Edited by Ricky_Brundritt Monday, October 31, 2016 7:04 PM
    • Marked as answer by leokom Monday, October 31, 2016 7:07 PM
    Monday, October 31, 2016 7:03 PM
  • Strange, I'm fairly certain this was working correctly not that long ago. It is expected that some memory would be used and not released when you load the map the first time as all the JavaScript for the map control is downloaded and still present in the browser after your dispose the map. If it wasn't you wouldn't be able to reload the map. However, after disposing and reloading there is a bit more memory used and if you dispose a second time that memory isn't released, which is an issue. I've logged this with the team to investigate. The team has a large number of performance tuning tasks that they are working on which include improved memory management.

    Note that disposing and reloading the map on a page is fairly uncommon and generally not recommended as each time you load a map it generates a new map session and thus a billable transaction. If you know you will be reusing the map on the page more than once, it is better to clear the data on the map and then hide the map rather than dispose of it. This will limit the memory usage and will also ensure that only a single map session is created per page load, and thus one billable transaction per page load.


    [Blog] [twitter] [LinkedIn]


    Thursday, December 29, 2016 10:16 AM

All replies

  • Use the maps dispose function. This will go through and clear all the entities, layers and events from the DOM and memory. No need to manually remove these.

    [Blog] [twitter] [LinkedIn]


    • Proposed as answer by Ricky_Brundritt Monday, October 31, 2016 7:03 PM
    • Edited by Ricky_Brundritt Monday, October 31, 2016 7:04 PM
    • Marked as answer by leokom Monday, October 31, 2016 7:07 PM
    Monday, October 31, 2016 7:03 PM
  • Thanks!
    Monday, October 31, 2016 7:07 PM
  • Has dispose been verified, it doesn't seem to work for me, no mater what I try. I have a map with several polygons on it ... I can see my map object in console.log in Microsoft Edge before I dispose it, task manager memory keeps climbing after disposing and recreating a new map with new data or layers.

    Thanks in advance

    geoMap.layers.clear();

    geoMap.dispose();


    JA

    Wednesday, December 28, 2016 8:52 PM
  • Strange, I'm fairly certain this was working correctly not that long ago. It is expected that some memory would be used and not released when you load the map the first time as all the JavaScript for the map control is downloaded and still present in the browser after your dispose the map. If it wasn't you wouldn't be able to reload the map. However, after disposing and reloading there is a bit more memory used and if you dispose a second time that memory isn't released, which is an issue. I've logged this with the team to investigate. The team has a large number of performance tuning tasks that they are working on which include improved memory management.

    Note that disposing and reloading the map on a page is fairly uncommon and generally not recommended as each time you load a map it generates a new map session and thus a billable transaction. If you know you will be reusing the map on the page more than once, it is better to clear the data on the map and then hide the map rather than dispose of it. This will limit the memory usage and will also ensure that only a single map session is created per page load, and thus one billable transaction per page load.


    [Blog] [twitter] [LinkedIn]


    Thursday, December 29, 2016 10:16 AM